I'm a new C++ programmer, i was so surprised that this trunk of code is able to be compiled by VS C++:
{
.......
int x;
x;
.......
}
x is a variable and I just wrote "x;" accidentally, i thought it would not be able to compiled but it did do. Would you tell me what was going? I tried to google but i could not find any thing valuable :(
You declared a variabel x. So, the program allocates four bytes of memory somewhere.
Then you write the statement x.
the compiler retrieves the value of x which is stored in the location that has been reserved for x in the previous step. The value itself is absolutly random since the for bytes have the value the just had prior to been allocated.
So, your line
x;
is a statement that simply posts a value that is immediately neglected since the compoiler does not have to act on it in any way.