Hii friends,
Is it possible to find the no. of elements in an array after inserting without counting while insertion
mjmythili
0
Newbie Poster
Recommended Answers
Jump to Postyou mean something like this
sizeof(array)/sizeof(type of array);
Jump to Post>>Is it possible to find the no. of elements in an array after inserting without counting while insertion
depends. For statically allocated arrays see andor's response. Otherwise, it is not possible because c arrays do not keep that kind of information.
If you are using C arrays and …
Jump to PostSo basically, no. All sizeof does is give you the size of the array, not the number of elements entered. You have to count as you insert.
Jump to PostThis works, even if you later want to change the type of the array, say from char to int:
length_of_array = sizeof(array)/sizeof(array[0]);
That doesn't work when the array is a parameter to a function
void foo(int ay[5]) { int length_of_array = sizeof(ay)/sizeof(ay[0]); printf("%d\n", length_of_array); printf("sizeof(ay) = %d\n" …
Jump to PostI dont know which more worse. Your ignorance about C or your stubbornness
All 23 Replies
andor
25
Posting Whiz in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
dragonheart
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
prabhakar1223
0
Newbie Poster
lich
-11
Junior Poster in Training
Prabakar
77
Posting Whiz
Asad_
-1
Newbie Poster
yellowSnow
commented:
For bumping old threads.
-1
joeoettinger
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
abhimanipal
91
Master Poster
dewi44
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
dewi44
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
dewi44
0
Newbie Poster
abhimanipal
91
Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
dewi44
0
Newbie Poster
dewi44
0
Newbie Poster
creeps
74
Junior Poster in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.