Help with Array

Super quick question about arrays and I am sure it has a very easy answer lol.

Can I add to an array that is defined by an int. I will give an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
for (ix = 0; ix < count; ++ix)
{
        numDifference = abs(highTemp[ix] - highTemp[ix + 1]);

	if (numDifference > maxValue)
	{
		largestDiff = numDifference;

		dayOne = day[ix];

		dayTwo = day[ix + 1];
	}
}


the [ix + 1] is that valid?

thanks in advance
It is valid, but it won't do what you think because of the next iteration of the for loop. This has the effect of overwriting your info.

Maybe you need 2 arrays - which is probably the more sensible thing to do.
okay so let me make sure I understand what you are saying to do.

I want to make sure that the second array call ( highTemp[ix + 1] ) doesn't overwrite my first array.. so I should make a copy of my highTemp to another temporary array then replace the highTemp[ix + 1] with my temporary array?
ix+1 is valid only if the arrays have such element. If an array has size count (or less), then on last iteration ix=count-1 and therefore ix+1 is not valid.
that makes a ton of sense thanks for clearing that up.. how would I be able to do something like that without getting the final error of ix+1 not being valid?

Iterate one element less.

Btw.maxValue and largestDiff .. intentional?
nope that is an error haha thank you for pointing that out
Topic archived. No new replies allowed.