%p和%x有什么区别吗?
独孤九剑贰 2013-11-22 12:51:52 #include <stdlib.h>
#include <stdio.h>
int main()
{
unsigned int *p;
p = (unsigned int *)malloc(100);
if(p)
printf("Memory Allocated at: %x",p);
else
printf("Not Enough Memory!\n");
getchar();
p = (unsigned int *)realloc(p,156);
if(p)
printf("Memory Realloc at: %x",p);
else
printf("Not Enough Memory!\n");
free(p);
getchar();
return 0;
}
在linux下编程有警告。
realloc.c: In function ‘main’:
realloc.c:8:10: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘unsigned int *’ [-Wformat=]
printf("Memory Allocated at: %x",p);
^
realloc.c:14:10: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘unsigned int *’ [-Wformat=]
printf("Memory Realloc at: %x",p);
但是用%p后可以解决,我想问下%p和%x有什么区别么?