C language study notes code comments-10

Table of contents

1. Annotation overview

2. Annotation type

3. Annotation principles

4. Annotation suggestion

Summarize


1. Annotation overview

       For a novice, annotations are relatively unfamiliar, but in reality it is relatively common. For example, if there are some difficult-to-understand classical Chinese texts in a Chinese book, there will be explanations in small fonts below, which is equivalent to translation, translating things that are difficult for others into things that are easy for everyone to understand. Similarly, in programming, code comments are explanations of the code, mainly to improve the readability of the code and make it easier for everyone to read.

2. Annotation type

1. Single-line comment: use // as the delimiter, // the right side is the relevant content of the comment

Example: printf("hello world!\n");  // output hello world! content

2. Multi-line comments: use /* */ as the delimiter, /* as the starting position of the comment content, */ as the end position of the comment content

example:

/*

Write a program that defines an integer and then enters its value.

*/

int a=1;

printf("a is %d!\n",a);

3. Annotation principles

1. Comments should be concise and clear;

2. In a complete development project, code comments should be standardized and unified;

3. When writing the code, corresponding comments should also be added, and the comments should also be modified synchronously when the code is modified;

4. Comments can be placed anywhere, even on the same line as the code, but a good comment style must be developed;

4. Annotation suggestion

1. The content of the notes should be concise and clear, there is no need to write those complicated and incomprehensible notes;

2. The comment style is uniform, use // or /**/, do not change frequently;

3. Do not insert comments in the middle of the code, unless necessary, otherwise it will reduce the readability of the code;

4. Describe the purpose of the code and the module function of the program design as much as possible, and provide users with useful information;

5. Note content should avoid duplication.

Summarize

       The content of the entire comment is not much, but many programmers don’t pay attention to this piece when writing code, which makes it difficult for subsequent programmers to maintain the existing code. It is recommended to form a good personal comment style. The written code is not only convenient for maintenance by yourself, but also convenient for others to maintain. Also, there are two ways to comment. It is not necessary to say that /**/ must be used. It is just a tool, and it is good to use it. Well, see you in the next chapter, come on!

Guess you like

Origin blog.csdn.net/weixin_37171673/article/details/132102680