count elements in an array
Hi, all!
do you know if there is any predefined function to count all the element in an array? or we have to write such functions ourselves?
for instance: if i have an array like this below:
Code:
int intMyArray[]={1,2,3,4,6,7};
how can we find out if there are 6 elements in the array intMyArray[] ??
usually, Iwrite
Code:
count = sizeof (intMyArray)/sizeof(int); // this work, it gives me correct value
however, when I pass the array to a function like,
Code:
#include <stdio.h>
int countArrayElement(int arr[]);
int main()
{
int intMyArray[]={1,2,3,4,6,7};
countArrayElement(intMyArray);
return 0;
}
int countArrayElement(int arr[])
{
int count = 0;
count = sizeof (arr)/sizeof(int); // wont work at all, arr is just the first element
return count;
}