Изменить это:
printf("Pointer: %s\n", pointer); // "%s" is for printing string
^
к этому:
printf("Pointer: %p\n", (void *)pointer); // "%p" is for printing pointer addresses
// Note: cast to (void *) is optional for use with
// character types (but idiomatic), and necessary
// for other types when using "%p" format specifier.
^
Здесь есть шпаргалка для спецификаторов формата printf
, включая один для адресов указателей .
Кстати, этот конкретный спецификатор формата также полезен для печати адреса других типов переменных при его использовании в сочетании с оператором &
( из ):
int int_var;
printf("This is the address of int_var: %p\n", (void *)&int_var);//note, (void *) cast is
//necessary here as its applied
//to non-character type.