A comment is text replaced during preprocessing by a single space character; the compiler therefore ignores all comments.
You can put comments anywhere the language allows white space. You cannot nest C-style comments inside other C-style comments. Each comment ends at the first occurrence of */.
You can also include multibyte characters; to instruct the compiler to recognize multibyte characters in the source code, compile with the -qmbcs option.
#include <stdio.h>
int main(void)
{
printf("This program has a comment.\n");
/* printf("This is a comment line and will not print.\n"); */
return 0;
}
This program has a comment.
#include <stdio.h>
int main(void)
{
printf("This program does not have \
/* NOT A COMMENT */ a comment.\n");
return 0;
}
This program does not have
/* NOT A COMMENT */ a comment.
/* A program with nested comments. */
#include <stdio.h>
int main(void)
{
test_function();
return 0;
}
int test_function(void)
{
int number;
char letter;
/*
number = 55;
letter = 'A';
/* number = 44; */
*/
return 999;
}
/* A program with conditional compilation to avoid nested comments. */
#define TEST_FUNCTION 0
#include <stdio.h>
int main(void)
{
test_function();
return 0;
}
int test_function(void)
{
int number;
char letter;
#if TEST_FUNCTION
number = 55;
letter = 'A';
/*number = 44;*/
#endif /*TEST_FUNCTION */
}
#include <stdio.h>
int main(void)
{
/*
printf("This line will not print.\n");
// This is a single line comment
// This is another single line comment
printf("This line will also not print.\n");
*/
return 0;
}