How to find the length of an INT array in C ?

Status
Not open for further replies.

sacrpio

Member level 3
Joined
May 24, 2004
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
500
INT ARRAY IN C

Dear Friend,
I have an int array, i want to find it's length how i can do. Array contains 0 also.

Suppose following is the array I have to find it's length. Please Help!!!!
int hello[]={1,2,3,0,4,3,9,7,5,6,0,6};
 

Re: INT ARRAY IN C

Try:
sizeof(hello)

best regards
 

Re: INT ARRAY IN C

sizeoff (int_array);

But if you pass this vector to a fuction by refrence you must pass its length to function, because "sizeoff (int_array);" will not work correctly at this function.
 

INT ARRAY IN C

The word "length" is unclear.
sizeof(hello) is the number of bytes.
sizeof(hello)/sizeof(*hello) is the number of elements.
 

Re: INT ARRAY IN C

Algo


get the sizeof Array sizeof(Array), It will give you sizeof(data type)*number of elements in Array

then get size of data type sizeof(*data type)

last sizeof(Array)/sizeof(*data type) this will give you total number of elements in Array

got it gr8
Deven
devennan@yahoo.com
 

INT ARRAY IN C

Hi,
the simplest way i think is
num of elements = sizeof(hello)/ sizeof(int)
 

INT ARRAY IN C

yes it's the easy way

sizeof(array)/sizeof(int);
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…