Home > Backend Development > C#.Net Tutorial > Detailed explanation of C language comments

Detailed explanation of C language comments

藏色散人
Release: 2020-02-26 17:00:48
Original
6114 people have browsed it

Detailed explanation of C language comments

When writing C language source code, you should use more comments to help understand the code. There are two comment methods in C language:

1. One is a block comment starting with /* and ending with */;

2. The other is A single-line comment starting with // and ending with a newline character.

(Recommended learning: c language video tutorial)

You can use /* and */ delimiters to mark comments within one line, or to mark comments on multiple lines. . For example, in the following function prototype, the ellipsis means that the open() function has a third parameter, which is optional. The comment explains the usage of this optional parameter:

int open( const char *name, int mode, … /* int permissions */ );
Copy after login

You can use // to insert a whole line of comments, or write the source code in a two-column format, with the program in the left column and the comments in the right column:

const double pi = 3.1415926536;       // pi是—个常量
Copy after login

In the C99 standard, single-line comments were officially added to the C language, but most compilers had begun to support this usage before C99. Sometimes they are called "C-style" comments, but in fact they are derived from BCPL, the predecessor of C.

In quotation marks, if /* or // are used to separate a character constant or string literal, they will not be considered the beginning of a comment. For example, the following statement has no comments:

printf("Comments in C begin with /* or //.\n" );
Copy after login

The preprocessor only detects characters in comments by checking the end of the comment, so block comments cannot be nested. However, source code containing single-line comments can be commented using /* and */:

/* 暂时注释掉这两行:
    const double pi = 3.1415926536;  // pi是一个常量
    area = pi * r * r;   // 计算面积
暂时注释到此 */
Copy after login

If you want to comment out part of the program containing block comments, you can use the conditional preprocessing command:

#if 0
  const double pi = 3.1415926536;   /* pi是一个常量      */
  area = pi * r * r ;  /* 计算面积     */
#endif
Copy after login

The preprocessor replaces each comment with a space. Therefore, min/*max*/Value becomes two tokens min Value.

For more programming-related learning, please pay attention to the php Chinese websiteIntroduction to ProgrammingVideo Tutorial Channel!

The above is the detailed content of Detailed explanation of C language comments. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template