What will be output of the following program?
#include<stdio.h>
int main(){
int x=100,y=20,z=5;
printf("%d %d %d");
return 0;
}
Explanation
Output:
Turbo C++ 3.0: 5 20 100
Turbo C ++4.5: 5 20 100
Linux GCC: Garbage values
Visual C++: 5
100 20
By default x, y, z are auto type data which are stored in stack in memory. Stack is LIFO data structure. So in stack first stores 100 then 20 then 5 and program counter will point top stack i.e. 5. Default value of %d in printf is data which is present in stack. So output is revere order of declaration. So output will be 5 20 100.
No comments:
Post a Comment