C Tutorial/Language/Comments
Содержание
Adding Comments
Comments in a C program have a starting point and an ending point.
Everything between those two points is ignored by the compiler.
<source lang="cpp">/* This is how a comment looks in the C language */</source>
Source code header comments
- At the beginning of the program is a comment block.
- The comment block contains information about the program.
- Boxing the comments makes them stand out.
The some of the sections as follows should be included.
- Heading.
- Author.
- Purpose.
- Usage.
- References.
- File formats. A short description of the formats which will be used in the program.
- Restrictions.
- Revision history.
- Error handling.
- Notes. Include special comments or other information that has not already been covered.
<source lang="cpp">/********************************************************
* hello -- program to print out "Hello World". * * * * Author: FirstName, LastName * * * * Purpose: Demonstration of a simple program. * * * * Usage: * * Runs the program and the message appears. * ********************************************************/ #include <stdio.h> int main() { /* Tell the world hello */ printf("Hello World\n"); return (0); }</source>
Hello World
The comments are enclosed in "/*...*/"
<source lang="cpp">#include <stdio.h> main(){
printf("Hi \n"); /* This is the comments.*/
}</source>
Hi
The "//" is used as single line comment
<source lang="cpp">#include <stdio.h> main(){
int i,j,k; i = 6; j = 8; k = i + j; printf("sum of two numbers is %d \n",k); // end of line comment
}</source>
sum of two numbers is 14
Using Comments to Disable
Comments are ignored by the compiler.
You can use comments to disable certain parts of your program.
<source lang="cpp">#include <stdio.h>
int main(){
/* printf("%15s","right\n"); */ printf("%-15s","left\n"); return(0);
}</source>
left