C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - Find Output of Program (Q.No. 9)
9.
What will be the output of the program?
#include<stdio.h>
#define FUN(arg) do\
{\
if(arg)\
printf("IndiaBIX...", "\n");\
}while(--i)
int main()
{
int i=2;
FUN(i<3);
return 0;
}
Answer: Option
Explanation:
The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.
Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.
Step 2: FUN(i<3); becomes,
do
{
if(2 < 3)
printf("IndiaBIX...", "\n");
}while(--2)
After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.
Hence the output of the program is "IndiaBIX... IndiaBIX..."
Discussion:
22 comments Page 3 of 3.
Shubh said:
6 years ago
Why there is \ in every line in macro.
Shwetal said:
2 years ago
If there is printf("India","bix");
the output will be = India.
And there would be a warning -too many arguments;
The second " " is simply ignored.
the output will be = India.
And there would be a warning -too many arguments;
The second " " is simply ignored.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers