C and pointer (pointers on C) -- Chapter 1: Quick Start

Source: Internet
Author: User

C and pointer (pointers on C) -- Chapter 1: Quick Start

Not quite the same as most people think that many programmers do not learn C well, so they should read this book.

I am writing as a reading note. Sometimes some questions and answers are attached.

To activate this type of column, we hope to encourage you as well!


Chapter 1: Quick Start

I always review and write. I think this chapter requires a certain C base for getting started.


Conclusion: stdio is proposed. h contains some basic functions, such as scanf (), printf (), getchar (), putchar (), gets (), and puts.
There are also some differences between NULL and NUL.
NUL, that is, the trailing character '\ n' in the string, does not exist or is being preprocessed.
NULL is a character defined in stdio, indicating that the pointer is NULL and the integer is 0.
EOF is also a defined character of stdio, which indicates that the Pointer Points to the end of the document.


Warning:
1. No & characters are added before the scalar parameter of the scanf function.
The first is the scalar parameter. For example, the array element parameter is a scalar parameter. It is passed between the main and the function through value transfer.
& The symbol is addressing here. If it is an array parameter, it is an address, so no addressing operation is required.
2. mechanically copy the format code of the printf function to the scanf function.
3. Misuse of the & operator where the & operator should be used.
One is a logical operator and the other is addressing. This problem can be avoided carefully.
4. misuse the = Operator instead of the = Operator to test equality.
Same as above, but it seems that more people make mistakes.
Especially in the if and while judgments.
For example, while (pointer = EOP)


Programming tips:
1. Use the # include command to avoid repeated declarations. At the same time, place the function prototype in # include.
2. Use the # define command to name constants.
3. Check their values before using the array subscript.
For example, ch = getchar ();
While (ch! = EOF & ch! = '\ N ')
Ch = getchar ();
This is a good habit.
4. assign values in the while/if expression.
For example:
Ch = getchar ();
While (ch! = EOF & ch! = '\ N ')
Ch = getchar ();
You can write it as follows:
While (ch = getchar ())! = EOF & ch! = '\ N ')
;
In this way, redundant statements can be eliminated. You can confidently claim that this code technique with poor readability should be avoided. I can tell you with confidence that this is because you are not very familiar with C.
You will not have any problems when reading the code.
5. Compile an empty loop body.
While (ch = getchar ())! = EOF & ch! = '\ N ')
;
This Semicolon is very important, otherwise the next irrelevant statement will be dragged into the while loop.
6. How to check to ensure that the array does not cross the border.
For example, in the stored array, the following must be included:
1. If the input row ends or the input row array is full, the loop break exists;
2. If the data space of the output row is insufficient, only values are assigned to the data that can be accommodated;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.