#include<stdio.h>
int fun();
int i;
int main()
{
while(i)
{
fun();
main();
}
printf("hello \n");
return 0;
}
int fun()
{
printf("hi");
}
answer is hello.how??wat is tat while(i) mean?

Answers were Sorted based on User's Feedback



#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / vignesh1988i

see first of all variable 'i' is declared as a global
storage class variable .. so according to that storage class
whenever we define an variable i before the main function
and explicatily we haven't initilized that variable means it
will defaultly variable i will have 0....
so when this while is compiled i has 0 which makes the loop
false.. so it will compile the very first statement after
that loop... so it prints hello...........


thank u

Is This Answer Correct ?    18 Yes 0 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / who cares

I am not an expert but you can try one thing that I did.

Remove the while loop and put the follow

if (i)
printf ( "hi\n" );


The result is that printf statement never gets any print
out! My guess would be because the value of 'i' is NOT
defined so, that while loop doesn't get assess at all! So,
the result is only "hello"

Is This Answer Correct ?    5 Yes 2 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / parul_kul

As "int i" is not defined/declared inside any function, by
default it is declared as external variable not as auto.
Thats why, it takes the 0 as its default value.

Is This Answer Correct ?    1 Yes 0 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / agita

in response to the previous answer...

there is no storage class specification for i..so by default
it
is auto..if an auto variable is not initiallized it would
give a garbage value..then how come while(0)....?

Is This Answer Correct ?    1 Yes 1 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / sudhir kumar sharma

if we try this program in case of above program we will come
to a conclusion that all the variable declared before main
are global and assigned a value by default to zero that's
why the while loop will not executed in the above program :)
#include<stdio.h>
#include<conio.h>
int a;
float b;
double c;
char d;
static int e;

int main()
{
clrscr();
printf("%d\n %f\n %d\n %c\n %d\n",a,b,c,d,e);
getch();
return 0;

Is This Answer Correct ?    0 Yes 0 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / tatukula

in above program variable 'i' is declared as global integer ..so i=0...thats why while() condition gets failed and
prints 'hello'

Is This Answer Correct ?    0 Yes 0 No

#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf(..

Answer / tanveer ahmed abbasi

hi hello

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

0 Answers  


When a c file is executed there are many files that are automatically opened what are they files?

0 Answers  


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

0 Answers   Infosys,


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

0 Answers  


How do you sort filenames in a directory?

0 Answers  






1. What will be the output of the following programs. a) #include <stdio.h> Main() { Int x=4; While(x==1) { X=x-1; Printf(“%d”,x); --x; } }

7 Answers   CSC,


Explain the difference between the local variable and global variable in c?

0 Answers  


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

2 Answers   Cap Gemini, HCL,


Is null always defined as 0(zero)?

0 Answers  


Write a code to remove duplicates in a string.

0 Answers   Expedia,


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

0 Answers  


What is a memory leak in structures? How can we rectify that?

2 Answers  


Categories