0

The outputs should be 10 and 40( considering sizeof(int) = 4) but while printing, sizeof(arr) is 4. Why is this so ? I am leaving a screenshot of my code below.

int n = 10, *arr;
arr = ( int * ) malloc ( sizeof(int) * n );

enter image description here

  • 1
    "The outputs should be ... 40" --> Disagree, `arr` is a pointer and not an array. The size of a pointer far more likely has a size of 4 or 8. – chux - Reinstate Monica Oct 02 '18 at 18:22
  • It is baffling *why* you want to find the size of the array, when in the line above, you *told* `malloc` the size to allocate - `sizeof(int) * n`. If you want to know if `malloc` was successfull, you check `arr == NULL`. – Weather Vane Oct 02 '18 at 18:37

0 Answers0