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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top