C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 11)
11.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i=1;
if(!i)
printf("IndiaBIX,");
else
{
i=0;
printf("C-Program");
main();
}
return 0;
}
Answer: Option
Explanation:
Step 1: int i=1; The variable i is declared as an integer type and initialized to 1(one).
Step 2: if(!i) Here the !(NOT) operator reverts the i value 1 to 0. Hence the if(0) condition fails. So it goes to else part.
Step 3: else { i=0; In the else part variable i is assigned to value 0(zero).
Step 4: printf("C-Program"); It prints the "C-program".
Step 5: main(); Here we are calling the main() function.
After calling the function, the program repeats from step 1 to step 5 infinitely.
Hence it prints "C-Program" infinitely.
Discussion:
11 comments Page 2 of 2.
Sanjeev said:
1 decade ago
When the main is called in the else part did the statement i=1 is again initialized or it retains the value of i=0....
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers