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

Discussion

Output of following C program?

#include <stdio.h>
#define max abc
#define abc 100
 
int main()
{
    printf("maximum is %d", max);
    return 0;
}

 

  • A.maximum is 100
  • B.abcimum is 100
  • C.100imum is 100
  • D.abcimum is abc

Answer: A

Correct answer: maximum is 100

Two rules combine. First, a macro is rescanned after substitution, so max expands to abc and abc then expands to 100. Second, macro replacement applies to tokens, not to text inside a string literal - so the max inside "maximum is %d" is untouched. The output is maximum is 100.

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

Post your comment

Please log in or register to post a comment.