Help me in Finding Length of an Integer Array in C...!!!


Recently I am having problem in finding Length of an Integer Array in C program.

Here is the case.

Consider in main() I have taken one integer array called a[]={1,2,3,4,5};
and Now I am passing this array to one function called myfunc i.e myfunc(int *p). Now In this function how to find length of this array…???

its not possible in c language.
for that you have to pass length as 2nd argument in function.

you can get size of array from calling function by using


chadii ma rehvu joie ho!!!
Mr. codingkamaster!!!

hello codingkamaster,the question what you have asked is indirect question about Garbage value,when we receive the array as pointer *p will point out the first array element…then successive elements are stored…
for(int i=0;i<n;i++)//n=limit
{if(a[i]>0)//considering you have given only positive values

         printf("\n %d %d",a[i],*(p+i));


``even this code fails because we don’t know about the garbage value…so we cant find as receiving as (int* p) in a function.,nxt is sizeof() is used…but u know this b4… this link may help you to create your own sizeof()function…link text1

Runtime allocated aaray’s size ditermination is impossible.
if array are static, global and local but Compile time allocated than sizeof function be used.
here U use myfunc(int *p) and pass the argument array name that only contain address of first byte of array so we not traverse to end of array.

So true eigen but select the statement that allocates memory at runtime and use the statements to determine size preceding that. Doing so even if the statement is traversed n number of times the size will be calculated for the most recent traversal…

In simple words, what you asked for IS NOT POSSIBLE.

dai macha very easy da
I will explain to you in java
int t=456;
eduku poi mukara

@eramit2010: I know that method bro… But I have not asked for that one…!!!

i have also given answer of what u have asked…

@kishan23: if u are not interested to answer the question genuinely then ____*off.

sizeof() function not perfectly on run time allocated array.
and traversing array we can’t predict the garbage value is +ve or -ve.

tamila paasuda

yes…its true…