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

Discussion

What will be the output of the following C code?

#include <stdio.h>
#define INDIA 1
#define US 2
#define CC US
main()
{
    #if CC==INDIA
    printf("Rupee");
    #elif CC==US
    printf("Dollar");
    #else
    printf("Euro");
    #endif 
}

 

  • A.Euro
  • B.Rupee
  • C.Dollar
  • D.Error

Answer: C

Correct answer: Dollar

CC expands to US, which expands to 2 - expansions are rescanned. The first test 2 == 1 fails, the #elif test 2 == 2 succeeds, so printf("Dollar") is the only line that reaches the compiler.

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

Post your comment

Please log in or register to post a comment.