C pointers - warning format "% x" expects arguments of type "unsigned int"

I am currently reading “Hacking the Art of Exploitation,” and there is an example that I seem to be unable to fix. Trying to compile the results with an error:

./addressof.c: In function 'main': ./addressof.c:8:4: warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'int *' [-Wformat] #include <stdio.h> int main() { int int_var = 5; int *int_ptr; int_ptr = &int_var; // Put the address of int_var into int_ptr. printf("int_ptr = 0x%08x\n", int_ptr); printf("&int_ptr = 0x%08x\n", &int_ptr); printf("*int_ptr = 0x%08x\n\n", *int_ptr); printf("int_var is located at 0x%08x and contains %d\n", &int_var, int_var); printf("int_ptr is located at 0x%08x, contains 0x%08x, and points to %d\n\n", &int_ptr, int_ptr, *int_ptr); } 

I understand where the error is, I just don't know how to fix it.

+6
source share
1 answer

Format specifier for the index %p , instead of %x . (See here )

+15
source

Source: https://habr.com/ru/post/910748/


All Articles