Summary of C language about notes
- 2020-07-21 09:24:36
- OfStack
When writing C source code, you should use annotations to help you understand the code. There are two ways to annotate in C:
1.1 Block comments that start with /* and end with */ (block comment);
2. The other is a single-line comment that starts with // and ends with a newline (line comment).
You can use the /* and */ delimiters to annotate comments within a line or multiple lines of comments. For example, in the following function prototype, the ellipsis means that the open() function has a third argument, which is optional. The comment explains the use of this optional parameter:
int open( const char *name, int mode, ... /* int permissions */ );
You can use // to insert an entire line of comments, or write the source code in two columns, with the program in the left column and the comments in the right column:
const double pi = 3.1415926536; // pi Is a constant
In the C99 standard, single-line annotations were officially added to the C language, but most compilers supported this usage before C99. Sometimes referred to as the "C++ style" annotation, it is actually derived from BCPL, the predecessor of C.
In quotes, if you use /* or // to separate 1 character constant or string literal (string literal), they are not considered the beginning of the comment. For example, the following statement is not commented:
printf("Comments in C begin with /* or //.\n" );
The preprocessor detects characters in a comment only by checking the end of the comment, so block comments cannot be nested. However, you can use /* and */ annotations to contain single-line annotations of the source code:
/* Comment out these two lines temporarily:
const double pi = 3.1415926536; // pi is 1 A constant
area = pi * r * r; // Calculating area
Comment this for the time being */
If you want to comment out parts of a program that contain block comments, you can use the conditional preprocessing command:
#if 0
const double pi = 3.1415926536; /* pi is 1 A constant */
area = pi * r * r ; /* Calculating area */
#endif
The preprocessor replaces each comment with a space. Therefore, min/*max*/Value becomes two tags min Value.
The above is the introduction of all the relevant knowledge points, thank you for your learning and support of this site.