C言語
C言語でソースコードにコメントを埋め込む
ソースコード中にコメントを埋め込みます。//は、//以降の文字列をコメントとして扱います。
//は、関数や変数への代入など、プログラム文の後ろに続けて書くことができます。
/* 〜 */は、囲まれた部分(〜)をコメントとして扱います。
/* */では複数行のコメントを書くことができます。
関数や変数への代入など、プログラム文の中に埋め込むこともできます。
/* */の中に/* */を入れ子にして書くことはできません。
comment.c
#include <stdio.h>
int main(void) {
// one line comment
printf("one line comment can write after statement\n"); // one line comment
/* This comment style can be written in multi lines like the following */
/*
line 1
line 2
*/
/* This comment style can be embedded in statement */
printf("This printf() statement line includes " /* comment */ "comment\n");
return 0;
}
実行結果
$ gcc comment.c -o comment
$ ./comment
one line comment can write after statement
This printf() statement line includes comment