Reputation: 5856
int test = 1;
cout << (long *) &test <<endl; //=0x7fff7370cefc
cout << (long) test <<endl; //= 1
Can someone explain what is happening in the first case? I get that long > int, thus the jibberish number, but what exactly is happening?
Upvotes: 0
Views: 682
Reputation: 1575
In this case:
cout << (long *) &test <<endl; //=0x7fff7370cefc
you in fact are giving the value, of the address of test
variable, to be converted into a long pointer value and then printed. Which is exactly what you should get.
Upvotes: 3