The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
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$ 
asked in Programming by Active (3k points)
edited by | 142 views
+1
20 and Size of pointer depends on machine. 4 for 32 bit and 8 for 64 bit. So, 20 8
0
B will be answer
0
20 4
0
the array is passed as the pointer, so the size of the pointer will be printed.
0
machine dependent

2 Answers

+2 votes
Best answer

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.

answered by Boss (10.3k points)
selected by
0 votes
20 8
answered by (39 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,047 questions
53,187 answers
184,496 comments
70,394 users