In this program, on using sizeof to compute no. of elements in array x, it works fine:
Code:
#include<stdio.h>
int main()
{
int x[5]={23,54,3,5,6};
int k=(sizeof(x)/sizeof(x[0]));
printf("%d\n",k);
return 0;
}
But, when I pass it as a parameter to a function, it gives incorrect result:
Code:
#include<stdio.h>
void fun(int x[])
{
int k=(sizeof(x)/sizeof(x[0]));
printf("%d\n",k);
}
int main()
{
int x[5]={23,54,3,5,6};
fun(x);
return 0;
}
It is also giving two different result on ideone and my system.
Why this is happening?