Programming Languages C Objective
Mar 09, 2013

What will be output of the following c code?

#define PRINT printf("Star Wars");printf(" Psycho");
#include<stdio.h>
void main()
{
 int x=1;
 if(x)
 PRINT
else
  printf("The Shawshank Redemption");
}

Choose the correct answer:
A) Star Wars
B) Psycho
C) Star WarsPsycho
D) Compiler error
Detailed Explanation

PRINT is macro constant. Macro PRINT will be replaced by its defined statement just before
the actual compilation starts.
If you are not using opening and closing curly bracket in if clause, then you can write
only one statement in the if clause.
You cannot write else clause without any if clause. It is cause of compilation error. Hence
compiler will show an error message: Misplaced else

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback