ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
#define N 5
#undef N
#define N 10
int main() {
    printf("%d", N);
}
  1. A. undefined (0)
  2. B. Compilation error: N is redefined
  3. C. 5
  4. D. 10

Correct answer: D. 10

#undef removes the previous definition of N entirely, so the subsequent #define N 10 is a fresh, unconflicting definition (not an illegal redefinition). By the time main is compiled, N expands to 10.

More C Programming questions

Exams that ask this topic