Summary
1) The compiler replaces the entire comment
2) backslash'\' is a continuation character, the compiler will remove the
backslash will automatically be continued to the previous line
// and /**/ in the string will be treated as slash characters, not as comments
4) /*..*/
comments cannot be nested
5) Attention
- Comments are used to describe the reason and intention of the program in
, rather than describing the sentences step by step
- Note
to avoid ambiguity, avoid abbreviations
- Note
should be streamlined to avoid bloat
Annotation
1. Is the following comment code correct?
spaces to replace the entire comment during the compilation process
- // and /*..*/ in the string
literal do not represent comment symbols
/*..*/
comments cannot be nested
According to the above regulations:
- Line10 is correct;
- The output of Line13 is "abcd // efgh";
- Line15 is correct,
'\' is a continuation character, which connects the content of the next line to the previous line;
- Line18 is wrong, the comment is replaced by a space and becomes in ti;
- Line20 error, cannot be nested in
/*..*/
2. Notes are used to explain the reasons and intentions, not to describe the running process of the program
Counterexample
int r = n/2; // r是n的一半
r++; // 变量r自增1
3. The comment must be unambiguous, and serve as a reminder to the code, avoid abbreviations
Counterexample
sad = 0x723; // R.I.P.L.V.B
The comment of this line of code makes people unable to understand what sad is and what does this value mean.
4. Comments are hints to the code to avoid being too bloated
Counterexample
/*
* b.s. 09/11/2021
* 这段代码这么写很不优雅
* 代码复杂,且时间、空间复杂度都较高
* 但我以后会去修改这段代码的
* 现在这么做因为交付压力较大
* 一定
*/
if(xx)
{
}
else
{
if(xx)
{}
else
{}
}
This article is summarized from "C Language Advanced Course" by Tang Zuolin from "Ditai Software Academy".
If there are any errors or omissions, please correct me.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。