ProgrammingVery hardProduct company OA

What is printed?

What is printed?
#define A 1
#define B (A + 1)
#undef A
#define A 10
int main(void) {
    printf("%d", B);
}
  1. A. 2
  2. B. 10
  3. C. Compilation error
  4. D. 11

Correct answer: D. 11

Macro bodies are expanded at the point of USE, not at the point of definition. B expands to (A + 1); since A is used where it currently equals 10 (after the #undef/#define), B becomes (10 + 1) = 11.

More C Programming questions

Exams that ask this topic