Monday, 4 July 2016

Can we initialize the variable with same variable while declaring?

No comments:
Guess the output?

int main()
double *ptr=ptr;
int a=a,b=10,c=b;
return 0;


Program compiles without any compilation error. And the output of the program is undefined.


Standard allows to declare the variable with same name. It is perfectly valid as per standard.
So what happens when we initialize like that?
Nothing will happen, only garbage value will be stored.

And the output of the program is undefined because garbage value can be anything.

No comments:

Post a Comment