Dealing with arrays

Im having trouble with dealing with arrays in c++, would someone please guide me on how to do something like below?

i want to set a value into an array, but don't want to overwite something already set in that array, instead i want it check if the array [] slot is not empty then if it's not empty, to go into an empty [] slot in that array to set its value, will appreciate any help!
Last edited on
By array do you mean:

type a[size];

or

array<type>(a); ?

If you're thinking of the first option, then you'll need to define empty:

For instance if it is of type int what's empty? A value of 0?

Remember that if you don't initialize an array and it's not made global it will have garbage in it.
Its a global array that will store values in it, it will be a float a[30] array, when i mean empty it will be set to 0, or not set at all, how would i do the above without overwriting any value in the array?
Not set at all is only safe if it is indeed global, don't forget this.

Algorithm:

check if the index you're trying to use is empty:

if it is, then assign value.

if it is not, look for one:

Go through all indexes until you find one that is empty. Assign to that index.
quote1
i want it check if the array [] slot is not empty then if it's not empty, to go into an empty [] slot in that array to set its value, will appreciate any help!


quote2
check if the index you're trying to use is empty:
if it is, then assign value.


I appreciate your efforts, but seriously how does quote one differ from quote 2? i am asking how to do this, a nice little example would be perfect.
I guess you've learn about if statements, use them. :)

be kind enough to share with us the code you've already written.
would ppl who actually read the post, start posting? appreciated :)
Topic archived. No new replies allowed.