C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 3)
3.
What will be the output of the program?
#include<stdio.h>
int i;
int fun();
int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}
Answer: Option
Explanation:
Step 1: int i; The variable i is declared as an integer type.
Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any arguments and it returns an integer value.
Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not execute the while block.
Step 1: printf("Hello\n"); It prints "Hello".
Hence the output of the program is "Hello".
Discussion:
30 comments Page 3 of 3.
Boopathy said:
1 decade ago
Global variable never gets initialized to zero. Unless you specify them.
Hema said:
1 decade ago
Ya its correct global variable are initialized to zero by default.
Pallavi Patil said:
1 decade ago
Hey any global variable is get initialized to zero automatically.
Sudher said:
1 decade ago
Yes by default all global variables are initialized to Zero(0)
Shilpi karn said:
8 years ago
main() function is inside main() so it give infinite loop.
Nikhil Prasad said:
9 years ago
What will be the output if 'while' condition gets true?
HarishMahajan said:
7 years ago
Why option Hi Hello not print?
Nikhil said:
1 decade ago
Why option B is not correct?
Hasshu said:
9 years ago
What is a global variable?
Shamil said:
3 years ago
I understand, thanks all.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers