Multiple choice

What will be the output of the following function?

define DIM1(array,type) sizeof(array)/sizeof(type)

int DIM2(int array[]) { return(sizeof(array)/sizeof(int)); } void main() { int arr[10]; printf(“%d %d “, DIM1(arr,int), DIM2(arr)); }

  1. 10 10

  2. 10 1

  3. 1 10

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

DIM1 is a macro that calculates the array size correctly (10) because the array name in that scope represents the whole array. In DIM2, the array decays into a pointer when passed as an argument, so sizeof(array) returns the size of a pointer, resulting in 1.