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 ?

  • Get the address, it's just a number - well, can you print the number? Hopefully putc allowed? - Harry
  • Use pointer-to-number conversion: (unsigned)pointer and (unsigned)(&pointer) . - ߊߚߤߘ
  • @Gosh Sominsky How are you going to output something without the output function? - Vlad from Moscow
  • Output where? In the file? On the screen? - bsuart
  • one
    @bsuart, explain what you think is the difference between output to a file or to the screen (control question: what is the file descriptor table and what is the default written in the first three elements?) - PinkTux

1 answer 1

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 int to intptr_t independently weakly? - Harry