![](/img/trans.png)
[英]How many ways are there to execute system command in C program for windows
[英]How many ways can comments be added in a C program?
当我从著名的 KR 书中解决一个问题以从 c 程序中删除评论时,我在互联网上搜索以了解可以在 C 程序中插入评论的所有可能情况,但没有找到该问题的任何完整答案. 所以我在这里添加这个问题的答案。 欢迎反馈。
在 C 程序中插入注释有几种方法?
当单行注释符号插入一行中的任何位置时,出现在换行符之前的所有内容都是注释的一部分。
任何类型的注释符号都可以出现在双引号字符串中——因此出现在双引号中的单行和多行注释符号不是注释; 它们是普通文本。
多行注释可以放在源代码中任何可以留空的地方。
在 C 中,注释不能嵌套。 在另一个多行注释中插入多行注释开始符号将截断第一个注释终止符号之后的注释部分。 检查#4的示例以清楚地理解。
#include <stdio.h>
#define TABSIZE /*false comment*/ 8
// this is a demo program. /* comment here */ XD example of #1
int main()
{
printf("#1 :- /* multiple */ and // single \n"); // example of #2
char str[40] = "/* multiple */ and // single"; // example of #2
printf("#2 :- %s\n", str);
char one /* example of #3 */ = 'x'; // example of #3
char two /* example of #3 */ = 'y'; // example of #3
printf("#3 :- %c and %c\n", one, two);
return /*example of #3 */ 0; // example of #3
/*(start1) this is a comment /*(start2) trying to- -- example of #4
insert an nested comment here */
// (e2) this part is not considered as comment */(e1).
// so to successfully run the program this part of the
// comment is handled by single line comment symbol '//'.
// remove all the '//' to see what happens.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.