Possible Duplicate:
Sizeof an array in the C programming language?
In my main function I have the following code:
struct student s1 = {"zack",0,0,82};
struct student s2 = {"bob",0,0,80};
struct student s3 = {"joe",0,0,97};
struct student s4 = {"bill",0,0,100};
struct student c[] = {s1,s2,s3,s4};
printf("%d\n\n", arrayLengths(c));
printf("%d\n\n", sizeof(c)/sizeof(c[0]));
where arrayLength is defined as:
int arrayLengths(struct student g[]) {
return sizeof(g)/sizeof(g[0]);
}
With duplicate code though I am getting two different results. My console output is:
0
4
What gives? Why is this so and how can I put this in its own function?