Hey Guys
I am trying to read into 10 integers then print them out
in reverse order using a simple one-dimensional array.
The below code compiles and does work but I am getting a garbage value before the output.
So say I entered 1 - 10 my ouput is: 125214 10 9 8 7 6 5 4 3 2 1
I am wondering why the program is generating this value
as I am not overstepping the bounds of the array. Any help appreciaited.
Code:#include <iostream> // main - begins program execution ///////////////////////////////////////////// // int main(int argc, char *argv[]) { const int ARRAY_SIZE = 10; int data[ ARRAY_SIZE ]; std::cout << "Enter ten integers: "; for ( int i = 0; i < ARRAY_SIZE; i++ ) { std::cin >> data[ i ]; } std::cout << "\nIn reverse order they are:\n\n"; for ( int i = ARRAY_SIZE; i >= 0; i-- ) { std::cout << data[ i ] << " "; } std::cin.get(); // freeze console output window std::cin.ignore(); return 0; // return value from main to OS }