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

Discussion

#include <stdio.h>
#define a 10
int main()
{
  printf("%d ",a);
 
  #define a 50
 
  printf("%d ",a);
  return 0;
}

 

  • A.Compiler Error
  • B.10 50
  • C.50 50
  • D.10 10

Answer: B

Correct answer: 10 50

The preprocessor works line by line, top to bottom, so the first printf is expanded while a still means 10 and the second after it has been redefined to 50. The output is 10 50. Redefining a macro to a different value without an intervening #undef is not strictly conforming, so a compiler will warn.

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

Post your comment

Please log in or register to post a comment.