# End of an Integer Array

Page 1 of 1

## 2 Replies - 688 Views - Last Post: 04 December 2010 - 06:59 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=203562&amp;s=1bb206e5647a8b7ba5b4a61c375e088a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 issyl

Reputation: -5
• Posts: 118
• Joined: 25-October 10

# End of an Integer Array

Posted 04 December 2010 - 06:33 AM

How will I determine the end of an integer array?

i tried something like this:

```int numbers[5];
int i = 0;
while(numbers[i] != '\0')
{

}

```

can anyone help me pls
Is This A Good Question/Topic? 0

## Replies To: End of an Integer Array

### #2 amir_ju

Reputation: 17
• Posts: 82
• Joined: 20-June 08

## Re: End of an Integer Array

Posted 04 December 2010 - 06:52 AM

the notation you've used is totally wrong. Because you can't be sure that the next element in memory is '\0' unless you have set that to zero like the string case. But this doesn't make sense, because in the strings '\0' is a special character not occurring at any position. But in an array,it's not clear that that zero indicates end of the array, or just a zero element. If you want to iterate over the array elements, a for from zero up to sizeof(numbers)/sizeof(int) solves the problem.
```int numbers[6];
cout <<(sizeof(numbers)/sizeof(int)) << endl;
for(int i=0; i<sizeof(numbers)/sizeof(int); i++){
}

```

But of course, the most reasonable way is to store the size of array in a number and use it for iteration.

### #3 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: End of an Integer Array

Posted 04 December 2010 - 06:59 AM

issyl, on 04 December 2010 - 10:33 PM, said:

How will I determine the end of an integer array?

That question means nothing as asked.
An array does not have an 'end'.
An array has boundaries.

Since you declare your array as follows
int numbers[5];
then the boundaries are element 0 and element 4.

Try and rethink your question in terms at what you have learned in class.
What is you are actually trying to do?
How does that requirement fit in with what you have been taught?

EDIT
For those interested in the history behind this question have a look here
http://www.dreaminco...ray-of-numbers/

This post has been edited by janotte: 04 December 2010 - 07:26 AM