C++
C++でソースコードにコメントを埋め込む
ソースコード中にコメントを埋め込みます。//は、//以降の文字列をコメントとして扱います。
//は、関数や変数への代入など、プログラム文の後ろに続けて書くことができます。
/*~*/は、囲まれた部分(~)をコメントとして扱います。
/* */では複数行のコメントを書くことができます。
関数や変数への代入など、プログラム文の中に埋め込むこともできます。
/* */の中に/* */を入れ子にして書くことはできません。
comment.cpp
#include <iostream>
int main(void) {
// one line comment
std::cout << "one line comment can write after statement" << std::endl; // 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 */
std::cout << "This statement line includes" /* comment */ "comment" << std::endl;
return 0;
}
実行結果
$ g++ comment.cpp -o comment
$ ./comment
one line comment can write after statement
This statement line includescomment