C dynamic memory allocation and sizeof()

前端 未结 7 1591
感情败类
感情败类 2020-12-12 02:42

I\'m having some trouble understanding the difference between these two code segments: I allocate space for an array of integers dynamically within my code with the followin

7条回答
  •  误落风尘
    2020-12-12 03:26

    You can't use sizeof with memory pointers:

    int *arr = calloc(cnt, sizeof(int));
    

    But it's ok to use it with arrays:

    int arr[8];
    

提交回复
热议问题