%p和%x有什么区别吗?
#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有什么区别么?
[解决办法]
%p 标准没有格式的规定, 打印出来像 0x%x 0X%08X %08X 啥格式的都有...
[解决办法]