سؤال

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