指针与数组的区别

 1 #include <stdio.h>
 2 int main()
 3 {
 4     double addr[10] = {12.23,13.412,1251.23,234.4,215.6,62.2,652.3,635.2,63.6,324.6};
 5     char *p_char;
 6     short *p_short;
 7     int *p_int;
 8     long *p_long;
 9     long long *p_long_long;
10     float *p_float;
11     double *p_double;
12     
13 /*
14     p_double = addr;    //指针可以更改指向。
15     addr = p_double;    //数组是不可更改指向的。
16     数组相当于 指针常量
17 */   
18 
19 
20     printf("sizeof(addr)        = %lu\n\n",sizeof(addr));//80   
21 
22     //指针在64位机中所占字节数 都是 8字节,这就是指针为什么这么高效的原因。
23     //指针与数组的区别:1.64位指针所占字节数永远,数组所占字节数是他的所有元素的字节数集合
24     printf("sizeof(p_char)      = %lu\n",sizeof(p_char));
25     printf("sizeof(p_short)     = %lu\n",sizeof(p_short));
26     printf("sizeof(p_int)       = %lu\n",sizeof(p_int));
27     printf("sizeof(p_long)      = %lu\n",sizeof(p_long));
28     printf("sizeof(p_long_long) = %lu\n\n",sizeof(p_long_long));
29     printf("sizeof(p_float)     = %lu\n",sizeof(p_float));
30     printf("sizeof(p_double)    = %lu\n",sizeof(p_double));
31     
32 
33     return 0;
34 }

 

posted @ 2021-02-28 01:03  王廷胡_白嫖帝  阅读(362)  评论(0编辑  收藏  举报