I have tried to make a program with the parameter %d in a pointer but it does not work, I changed to %p, but that is for the address, I want to print the value. This is the error
gcc null_Pointer.c -o null_Pointer null_Pointer.c: In function ‘main’: null_Pointer.c:7:35: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat=] 7 | printf("The value of ptr is : %x\n", ptr ); | ~^ ~~~ | | | | | int * | unsigned int | %ls
this is the code
#include <stdio.h>
int main () {
int *ptr = NULL;
printf("The value of ptr is : %x\n", ptr );
return 0;
}
%p
. – Fiddling Bitsvoid *
, assuming you want to print the address held by the pointer. – Sourav Ghoshptr
, to print the value, like this:*ptr
. If it's not pointing to a validint
address though you'd invoke undefined behavior. – Fiddling Bits*ptr
, what would invoke UB in your caseptr == NULL
. – Ingo Leonhardt