C/Language Basics/Comments
Comments in C
<source lang="cpp"> /* This is a single line comment */ /*
* This is a mult-line * comment. */
int main() {
/* A procedure */ int i; /* Comment / code line */ char charArray[10]; strcpy(charArray, "abc"); /* String */ strcpy(charArray, "a\"bc"); /* String with quotation */ charArray[0] = "a"; /* Character */ charArray[1] = "\""; /* Character with escape */ i = 3 / 2; /* Slash that"s not a commment, divide operator */ i = 3; /* Normal number */ i = 0x123ABC; /* Hex number */ i = ((1 + 2) * /* Nested () */ (3 + 4)); { int j; /* Nested {} */ } return (0);
}
</source>
One line comments
<source lang="cpp">
- include <stdio.h>
- include <stdlib.h>
int avg(int a,int b) {
return (a + b)/2;
} int main() {
int i, j; int answer; /* comments are done like this */ i = 7; j = 9; answer = avg(i,j); printf("The mean of %d and %d = %d\n", i, j, answer); exit (0);
}
</source>