¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 12:36:14

¶¯Ì¬ÄÚ´æ·ÖÅä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¸ö×Ö½ÚÂð£¿

zltzlt ·¢±íÓÚ 2020-7-29 12:45:45

arr ÊÇÒ»¸öÖ¸Õë

sunrise085 ·¢±íÓÚ 2020-7-29 12:47:58

arrÊÇÒ»¸öÖ¸Õë¡£Æä´óСÓëÄãµÄÊý×é´óСû¹Øϵ£¬ÓëÄãµÄϵͳÓйأ¬32λϵͳ¾ÍÊÇ4×Ö½Ú£¬64λϵͳ¾ÍÊÇ8×Ö½Ú¡£

¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 13:10:01

sunrise085 ·¢±íÓÚ 2020-7-29 12:47
arrÊÇÒ»¸öÖ¸Õë¡£Æä´óСÓëÄãµÄÊý×é´óСû¹Øϵ£¬ÓëÄãµÄϵͳÓйأ¬32λϵͳ¾ÍÊÇ4×Ö½Ú£¬64λϵͳ¾ÍÊÇ8×Ö½Ú¡£

¿É²»¿ÉÒÔ¿´³ÉÊÇÒ»¸öÊý×éÃûÄØ£¿

livcui ·¢±íÓÚ 2020-7-29 14:12:38

±¾Ìû×îºóÓÉ livcui ÓÚ 2020-7-29 14:13 ±à¼­

¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 13:10
¿É²»¿ÉÒÔ¿´³ÉÊÇÒ»¸öÊý×éÃûÄØ£¿

²»ÄÜ¿´³ÉÊý×éÃû£¬µ«´ó²¿·ÖÇé¿öÏ¿ÉÒÔµ±Êý×éÃûʹÓã¬

µ«ÄãµÄ sizeof(arr) ´«ÈëµÄÊÇÖ¸Õë

¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 15:07:11

livcui ·¢±íÓÚ 2020-7-29 14:12
²»ÄÜ¿´³ÉÊý×éÃû£¬µ«´ó²¿·ÖÇé¿öÏ¿ÉÒÔµ±Êý×éÃûʹÓã¬

µ«ÄãµÄ sizeof(arr) ´«ÈëµÄÊÇÖ¸Õë

ºÃµÄллdl

livcui ·¢±íÓÚ 2020-7-29 15:10:06

¡¸¤¦¤¿¤«¤¿¡¹ ·¢±íÓÚ 2020-7-29 15:07
ºÃµÄллdl

ÉèÖÃ×î¼Ñ{:10_256:}
Ò³: [1]
²é¿´ÍêÕû°æ±¾: ¶¯Ì¬ÄÚ´æ·ÖÅäcalloc