2011-08-27 30 views
4

这是一个面试问题,我最近问:
C代码来检测,如果编译器允许注释嵌套

编写一个编译和运行时,一个C程序,打印出一条提示信息 是否编译器,它是编译的,允许/ * */ 对嵌套的评论

如何去做这件事?

+0

功课?如果是这样,请标记为。你有什么尝试? – amit

+0

我认为目前我的互联网连接存在一些问题。 所以这个问题甚至在我想提交之前就已经提交。 –

+0

已经关闭。但是? –

回答

13
int noNesting = 0 /* /* */ + 1 // */ 
; 
+0

+1,但这只会在C++评论可以接受时才有用。 –

0
int main(void) 
{ 
int temp=0 /* /* */ + 1 // */ 
; 
    //if nesting allowed temp value woud be 0 otherwise it would be 1 
if(temp) 
{ 
printf("Nesting not allowed"); 
} 
else 
{ 
printf("Nesting allowed"); 
} 
return 0; 
}