Multiple choice technology

What is the output of the following code? # include<stdio.h># define a 10 main() { printf("%d..",a); foo(); printf("%d",a); } void foo() { #undef a #define a 50 }

  1. 10..10

  2. 10..50

  3. Error

  4. 0

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The #define creates a macro substitution that happens during preprocessing. When foo() is called, the #undef and # redefine inside it only affect that function's scope during compilation; they don't retroactively change the value already printed. The first printf uses the original a=10, and the second printf also uses a=10 because the # undef/#define in foo() happens after the first printf and doesn't affect already-processed code.