142 views
#include<stdio.h>
void temp(int a[]);
main(){
int a[5]={1,2,3,4,5};
printf("%d", sizeof(a));
temp(a);
}

void temp(int a[]){
printf(" %d", sizeof(a));
}

Output of above code is, given size of int is 4 byte

1. $20$ $20$
2. $20$ $8$
3. $8$ $8$
4. $8$ $20$
edited | 142 views
+1
20 and Size of pointer depends on machine. 4 for 32 bit and 8 for 64 bit. So, 20 8
0
0
20 4
0
the array is passed as the pointer, so the size of the pointer will be printed.
0
machine dependent

In main()

printf("%d" , sizeof(a))  gives size of the array i.e number of elements * size of the element = 5*4 = 20bytes

When the array is passed as the parameter, it is treated as a pointer.So the sizeof(a) in the function will give the size of the pointer either 4 or 8 depending on the machine.

selected by
20 8

+1 vote
1
2
+1 vote