这是一道面试题:-
Write a C program which when compiled and run, prints out a message indicating whether the compiler that it is compiled with, allows /* */ comments to nest.
这个问题的解决方案如下:-
Sol:- 你可以有一个整数变量嵌套:
int nest = /*/*/0*/**/1;
如果它支持嵌套评论,则答案为 1,否则答案为 0。
这是如何工作的?我不明白变量声明。
最佳答案
如果编译器不允许嵌套,第一个 */
将终止多行注释的打开,这意味着 0
不会被注释掉。写有一些空格:
int nest = /*/*/ 0 * /**/ 1;
导致代码
int nest = 0 * 1; // -> 0
如果它允许嵌套,它将是
int nest = /*/*/0*/**/ 1;
导致
int nest = 1;
关于c++ - C/C++ 中的嵌套注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6698039/