#include <stdio.h>
int avg(int []);
void main(){
int average;
int marks[5]={10,15,20,30,45};
printf("%d\n",sizeof(marks)); // answer is 20(as expected)
avg(marks);
}
int avg(int marks[]){
int sum=0;
printf("%d\n",sizeof(marks)); // answer is 8(why???)
}
In this code, I was trying to print the sizeof the integer pointer marks. When I print the sizeof the marks inside the main method it gives 20 as the result as we expected. But the same object passes to the avg function and prints the sizeof marks it shows the result as 8. I couldn’t understand why that was happening.
Can anyone please clarify this?
Any help would be appreciated.
>Solution :
It is size of the int*, which is 8 on your system.