C Tutorial/Language/Comments — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Текущая версия на 10:32, 25 мая 2010
Содержание
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.
/* This is how a comment looks in the C language */
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.
/********************************************************
* 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);
}
Hello World
The comments are enclosed in "/*...*/"
#include <stdio.h>
main(){
printf("Hi \n"); /* This is the comments.*/
}
Hi
The "//" is used as single line comment
#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
}
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.
#include <stdio.h>
int main(){
/* printf("%15s","right\n"); */
printf("%-15s","left\n");
return(0);
}
left