首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

%p跟%x有什么区别吗

2013-11-23 
%p和%x有什么区别吗?#include stdlib.h#include stdio.hint main(){unsigned int *pp (unsigned in

%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 啥格式的都有... 
[解决办法]

引用:
%p打印地址的啊! %x十六进制形式打印  完成不同!


%p
void *; print as a pointer (implementation-dependent representation).

热点排行