edited by
502 views
0 votes
0 votes
#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 by

1 Answer

Best answer
2 votes
2 votes

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

Related questions

0 votes
0 votes
0 answers
1
1 votes
1 votes
2 answers
4