¶¯Ì¬ÄÚ´æ·ÖÅäcalloc
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int *arr = NULL;
int num = 0;
printf("ÇëÊäÈëÊý×ֵĸöÊý:");
scanf("%d", &num);
arr = (int *)calloc(num, sizeof(int));
int i = 0;
for (i = 0; i < num; i++) {
printf("ÇëÊäÈëµÚ%d¸öÔªËØ:", i);
scanf("%d", &arr);
}
for (i = 0; i < num; i++) {
printf("arr[%d] = %d\n", i, arr);
printf("arr + %d = %p\n", i, arr + i);
}
printf("%d\n", sizeof(arr));
printf("%d\n", sizeof(arr));
int n = sizeof(arr) / sizeof(arr);
printf("n = %d\n", n);
printf("%d", arr);
free(arr);
return 0;
}
ÊäÈënum = 4, arr = 23, arr = 34, arr = 35, arr = 9, ΪʲôÊä³öµÄʱºòsizeof(arr) = 8?²»Ó¦¸ÃÊÇ16¸ö×Ö½ÚÂ𣿠arr ÊÇÒ»¸öÖ¸Õë arrÊÇÒ»¸öÖ¸Õë¡£Æä´óСÓëÄãµÄÊý×é´óСû¹Øϵ£¬ÓëÄãµÄϵͳÓйأ¬32λϵͳ¾ÍÊÇ4×Ö½Ú£¬64λϵͳ¾ÍÊÇ8×Ö½Ú¡£ sunrise085 ·¢±íÓÚ 2020-7-29 12:47
arrÊÇÒ»¸öÖ¸Õë¡£Æä´óСÓëÄãµÄÊý×é´óСû¹Øϵ£¬ÓëÄãµÄϵͳÓйأ¬32λϵͳ¾ÍÊÇ4×Ö½Ú£¬64λϵͳ¾ÍÊÇ8×Ö½Ú¡£
¿É²»¿ÉÒÔ¿´³ÉÊÇÒ»¸öÊý×éÃûÄØ£¿ ±¾Ìû×îºóÓÉ livcui ÓÚ 2020-7-29 14:13 ±à¼
¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 13:10
¿É²»¿ÉÒÔ¿´³ÉÊÇÒ»¸öÊý×éÃûÄØ£¿
²»ÄÜ¿´³ÉÊý×éÃû£¬µ«´ó²¿·ÖÇé¿öÏ¿ÉÒÔµ±Êý×éÃûʹÓã¬
µ«ÄãµÄ sizeof(arr) ´«ÈëµÄÊÇÖ¸Õë livcui ·¢±íÓÚ 2020-7-29 14:12
²»ÄÜ¿´³ÉÊý×éÃû£¬µ«´ó²¿·ÖÇé¿öÏ¿ÉÒÔµ±Êý×éÃûʹÓã¬
µ«ÄãµÄ sizeof(arr) ´«ÈëµÄÊÇÖ¸Õë
ºÃµÄллdl ¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 15:07
ºÃµÄллdl
ÉèÖÃ×î¼Ñ{:10_256:}
Ò³:
[1]