Author |
Topic: Nested Comments (Read 905 times) |
|
william wu
wu::riddles Administrator
Gender:
Posts: 1291
|
|
Nested Comments
« on: Apr 12th, 2003, 1:58pm » |
Quote Modify
|
Write a C program that prints "true" if the compiler handles nested comments, and "false" if not. Source: Yosen Lin
|
« Last Edit: Apr 12th, 2003, 6:32pm by william wu » |
IP Logged |
[ wu ] : http://wuriddles.com / http://forums.wuriddles.com
|
|
|
Pietro K.C.
Full Member
Gender:
Posts: 213
|
|
Re: Nested Comments
« Reply #1 on: Apr 13th, 2003, 9:23am » |
Quote Modify
|
How about this? I'm not sure if a non-nested-comment compiler will accept it, though, because of the */ left over at the end. int main() { int a = 1; /* /**/ a = 0; /**/ */ if(a == 1) { printf("true"); } else printf("false"); return 1; }
|
« Last Edit: Apr 13th, 2003, 9:24am by Pietro K.C. » |
IP Logged |
"I always wondered about the meaning of life. So I looked it up in the dictionary under 'L' and there it was --- the meaning of life. It was not what I expected." (Dogbert)
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: Nested Comments
« Reply #2 on: May 29th, 2004, 4:00pm » |
Quote Modify
|
int nested(){ return 1/* /**/ *0*/*1* /**/1; } if nested: return 1/* /**/ *0*/*1* /**/1; return 1*1* 1; if not nested: return 1/* /**/ *0*/*1* /**/1; return 1 *0*1;
|
|
IP Logged |
|
|
|
tseuG
Junior Member
Gender:
Posts: 62
|
|
Re: Nested Comments
« Reply #3 on: Jul 12th, 2004, 9:08am » |
Quote Modify
|
Another approach: char *truth = /* /* */ " */ " /* " /* */; if nested comments work, truth = " /* " if they don't, truth = " */ "
|
|
IP Logged |
|
|
|
|