Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output for the following code snippet?

#include <stdio.h>
#define A -B
#define B -C
#define C 5

int main()
{
  printf("The value of A is %d\n", A); 
  return 0;
} 

 

  • A.The value of A is 4
  • B.The value of A is 5
  • C.Compilation Error
  • D.Runtime Error

Answer: B

Correct answer: The value of A is 5

Macros are rescanned after expansion, so the substitution cascades:

A → -B → -(-C) → -(-5)

Two negations cancel, so the value printed is 5.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.