Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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};
 

C-Man

Advanced Member level 4
Joined
Jul 19, 2001
Messages
1,059
Helped
90
Reputation
180
Reaction score
17
Trophy points
1,318
Activity points
10,191
Re: INT ARRAY IN C

Try:
sizeof(hello)

best regards
 

Zerox100

Full Member level 6
Joined
Mar 1, 2003
Messages
320
Helped
21
Reputation
42
Reaction score
10
Trophy points
1,298
Activity points
2,509
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.
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
636
Reputation
1,270
Reaction score
88
Trophy points
1,328
Location
USA
Activity points
33,183
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.
 

devennan

Member level 3
Joined
May 7, 2004
Messages
66
Helped
5
Reputation
10
Reaction score
1
Trophy points
1,288
Location
India
Activity points
798
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
 

sshahid47

Advanced Member level 4
Joined
Nov 5, 2004
Messages
101
Helped
15
Reputation
30
Reaction score
2
Trophy points
1,298
Activity points
974
INT ARRAY IN C

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

shafee001

Advanced Member level 4
Joined
May 6, 2004
Messages
114
Helped
16
Reputation
32
Reaction score
4
Trophy points
1,298
Location
Egypt
Activity points
1,078
INT ARRAY IN C

yes it's the easy way

sizeof(array)/sizeof(int);
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top