The while loop will terminate when an invalid data type (something that isn't a double) or an EOF (end-of-file) is entered.
If you input a character, the loop will exit. In the console, if you type ctrl+z (an eof), the loop will exit.
i++ is the post-increment operator, meaning it will increment the object
after it is used.
Example:
1 2
|
int i = 5;
cout << i++ << ", " << i << endl;
|
would output:
++i is the pre-increment operator, which will increment the object
before it is used.
Example:
1 2
|
int i = 5;
cout << ++i << ", " << i << endl;
|
would output:
In general, there are advantages to using the pre-increment operator over the post-increment operator (speed and memory use), unless the use of post-increment is being taken advantage of, as in the first example.
The way I think of it is, pre-increment might be faster than post-increment, but post-increment will never be faster than pre-increment.
So I generally recommend using post-increment
only when you are taking advantage of it's functionality; use pre-increment everywhere else.
If you were to write functions for these two, they would look something like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
int postIncrement(int number)
{
int temp = number; //additional step involved in postIncrement.
number = number + 1;
return temp;
}
int preIncrement(int number)
{
number = number + 1;
return number;
}
|
EDIT: Tiny addition and spelling.