Código C para detectar si el compilador permite que los comentarios se aniden

This is an interview Question that i was asked recently:

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

How to go about this ?

preguntado el 27 de agosto de 11 a las 13:08

homework? if so, please tag it as so. what have you tried? -

I think there is some problem with my internet connection currently. so the question got submitted even before i wanted to submit. -

@amit: i am clueless how to go about this one ? -

int puts();int main(){puts("no");}, es decir, un C compiler does not allow comments to nest. -

Perhaps more to the point, I consider assignments/exercises like this perjudicial because they wrongly teach that C is an un[der]specified language where compilers might vary in how they parse/compile programs, and lead to new C programmers jumping through all sorts of obfuscated loops to be "portable" to "C compilers" that don't and can't exist. -

2 Respuestas

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

Respondido 27 ago 11, 18:08

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

Respondido el 11 de Septiembre de 12 a las 14:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.