Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sizeof() gives different results for the same object

#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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is size of the int*, which is 8 on your system.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading