C - What is the output: sizeof int array


What is the output from the following code

#include <stdio.h>

int main()
    int array[5];

    printf("The array has a size of %u.\n",sizeof(array));

Click to view the answer

The array has a size of 20.


An int array of 5 elements occupies 20 bytes of storage because each int value uses 4 bytes: 5 times 4 = 20.

If the array were declared as a double of 5 elements it would use 40 bytes of storage.

That's because the size of a double is 8 bytes.

Related Quiz