Determine Output:
#include <stdio.h>
#define a 10
void main()
{
#define a 50
printf("%d", a);
}
Answer: A
Correct answer: 50
The preprocessor works on the text in order and takes no notice of braces, so the second #define is in force by the time the printf line is expanded - and the program prints 50. Redefining a macro to a different value without an intervening #undef is not strictly conforming, so expect a warning.
Please log in or register to report this question.