Hi there, I am fairly new to C++. I am wondering why in my for loop I use i <= (ARRAY_SIZE -1); To me I read it as: 0 less than or equal too (3-1). Also when I display my elements, I use words[i]. Can someone please explain how and why this works. Any feedback would be greatly appreciated! Thanks in advance! Eagle
That is equivalent to a more common: for (int i = 0; i < ARRAY_SIZE; i++)
In both cases the i is initialized to 0.
One iteration succeeds, because 0 < 3 (or 0 <= 2) is true.
Second iteration succeeds, because 1 is still a small number.
Third time i=2. 2 is still less than 3, or in your version 2 is less than equal to 3.
Fourth time. 3 is not longer less than 3, nor equal to 2, so there will be no fourth iteration.