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
Your second
printf()should take a"%p\n"format, and strictly a cast:The number of machines where the cast actually changes anything is rather limited.