Search code examples
cprintingunsigned-integer

How to print an unsigned int* in c?


I tried to print an unsigned int* in C. I used %X but the compiler said:

" format %x expects argument of type unsigned int, but argument 3 has type unsigned int* ".

I also used "%u" but I got the same error again.

Can anybody help me?


Solution

  • If you want to print a pointer, you need to use %p format specifier and cast the argument to void *. Something like

     printf ("%p", (void *)x);
    

    where x is of type unsigned int*.

    However, if you want to print the value stored at x, you need to dereference that, like

    printf ("%u", *x);