How to make your code look more advanced---Exploration Edition (1)

How to make your code look more advanced (1)

1. Types of comments

There are two main types of C language comments:

1. The format is /* comment content*/

/* Comment content*/, introduced by the C89 standard.

This comment can be a single line or multiple lines.

2. The format is //comment content

//Comment content, this is a single-line comment, introduced by the C99 standard.

Most compilers are compatible with both annotations.

2. Use notes skillfully

Error example

#include <stdio.h>
//int i;
int main ()
{
//i++;
//if(i>100) i=0;
printf("hello world");
}

The above code does not look advanced, and there is no explanation of the comments, making it difficult to understand the code at a glance. . .

Modify as follows

/***
*******************************************************
**author:小邱
**function:main.c
**date:2023.8.8
*******************************************************
***/
#include <stdio.h>
int main ()
{
    printf("hello world"); /*打印hello world输出测试*/
}

Delete unnecessary comments in the code, keep only the necessary code, and write the functional content after the important code, as above. Doesn’t this look a little more advanced than the above?

3. Tips for annotation

1. Annotate the function, author and date of this file in each header file (various c and h files). The content of the annotation can be referred to the following:

/***
*******************************************************
**author:小邱
**function:main.c
**date:2023.8.8
*******************************************************
***/

2. Comments in the code

2.1 Comment the code

If you are commenting on code, use // for a single line of code and /* */ for a single line of code.

2.2 Explanation of the code

Sometimes we need to explain the code content. At this time, it is best not to use "//comment content" for comments. This kind of comment is relatively untidy, so try to use "/* / ". Personally, I think "/ */" is more suitable for explanation.

If there is a lot of code content, it is recommended to explain it together instead of explaining it separately.

Guess you like

Origin blog.csdn.net/weixin_58125062/article/details/132645633