Tuesday 23 April 2013

int vs static int


What will be output if you will compile and execute the following c code?

void main(){
int i=10;
static int x=i;
if(x==i)
printf("Equal");
else if(x>i)
printf("Greater than");
else
printf("Less than");
}


(A) Equal

(B) Greater than

(C) Less than

(D) Compiler error

(E) None of above


________________________________________
Explanation:
static variables are load time entity while auto variables are run time entity. We can not initialize any load time variable by the run time variable.
In this example i is run time variable while x is load time variable.

No comments:

Post a Comment