Suppose I have a variable, I write its address in the pointer. How can I print the pointer address and the address of the variable that is stored in the pointer without printf ?
1 answer
I will not squeeze a comment, so the answer is ... See here - http://ideone.com/jVhnOs
int main(int argc, const char * argv[]) { int a; printf("%p\n",&a); intptr_t p = (intptr_t)&a; char s[2*sizeof(p)]; for(int i = 2*sizeof(p)-1; i >= 0; --i) { s[i] = "0123456789ABCDEF"[p & 0x0F]; p >>= 4; } for(int i = 0; i < 2*sizeof(p); ++i) { putc(s[i],stdout); } } - Good, plus !!! (and 4 more characters needed for comment) - Majestio
- Did you try 64 bits? - 0andriy
- @ 0andriy And to change
unsigned inttointptr_tindependently weakly? - Harry
|
putcallowed? - Harry(unsigned)pointerand(unsigned)(&pointer). - ߊߚߤߘ