The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
151 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 (2.6k points)
edited by | 151 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.4k 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
49,793 questions
54,514 answers
188,332 comments
75,181 users