指针的大小

来源:互联网 发布:正在激活windows 错误 编辑:程序博客网 时间:2024/05/17 07:19
#include <stdio.h>typedef struct str_test{    int a;    char b;    float c;}str_test;str_test* str_test_ptr;int * int_ptr;int main(void){    printf("************0**********\n");    printf("sizeof(str_test_ptr):%d\n",sizeof(str_test_ptr));    printf("sizeof(int_ptr):%d\n",sizeof(int_ptr));    printf("sizeof(str_test_ptr):%d\n",sizeof(str_test_ptr));    printf("sizeof(int_ptr):%d\n",sizeof(int_ptr));}


输出结果

************0**********
sizeof(str_test_ptr):8
sizeof(int_ptr):8


/usercode/file.cpp: In function ‘int main()’:
/usercode/file.cpp:14:62: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
     printf("sizeof(str_test_ptr):%d\n",sizeof(str_test_ptr));
                                                              ^
/usercode/file.cpp:15:52: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
     printf("sizeof(int_ptr):%d\n",sizeof(int_ptr));
                                                    ^
所以指针大小都是4字节大小,在32位系统中

 

原创粉丝点击