I was trying to print the address of the pointer variable not the address where it is pointing to, could anyone assist me in achieving that? Below is what I am trying but it is showing warning which i am not able to resolve. Thanks!
#include <stdio.h>
#include <stdlib.h>
int main()
{
int* y;
printf("%p\n",y);
printf("%x\n",&y);
y = (int*)malloc(sizeof(int));
printf("%p\n",y);
printf("%x\n",&y);
return 0;
}
Compilation warning:
Warning: format ‘%x’ expects argument of type ‘unsigned int’,
but argument 2 has type ‘int **’
Output:
0xb773fff4
bfa3594c
0x8361008
bfa3594c
&correctly -- the printf hints are just hintsyand&yare pointer values. Why are you using%pto print one pointer value, but suddenly switch to%xfor another pointer value? All of yourprintfstatements are printing pointers, which means that all of them should use%p.