Advanced C language: 12. Comment symbols

Are annotations important?

Please observe the code below and judge whether the following comments are correct?

intmain()
{
	int/*...*/i; //right space replacement
	char* s = "abcdefg     //ijklmn";		//right
	// Is it a \ //right newline
		valid comment?						//right
	in/*...*/tj; //error error after space replacement
	
	return 0;
}

Annotation rules:

        The compiler replaces the entire comment with a space during compilation;

        // and /*...*/ in string literals do not represent comment symbols;

        /*...*/ type comments cannot be nested.

Interesting question:

What does the following line of code mean?

y=x/*p

The author's original intention: assign the result of dividing x by *p to y.

Compiler: Use /* as the beginning of a comment, and treat the content after /* as a comment until */ appears.

From the compiler's point of view, comments and other elements are equal. Therefore, as an engineer, comments cannot be taken lightly.

Modification: y = x/ *p; //add space

Comments are used to explain why and intent, not to describe how a program works.

Writing comments is not about writing moods. It must be unambiguous and play a role in prompting the code, avoiding the use of abbreviations.

Comments are hints to the code to avoid bloat and distraction.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325576817&siteId=291194637