Feb 28, 2013 at 12:14pm Feb 28, 2013 at 12:14pm UTC
I need help understanding something simple.
How many times does the following loop execute, and what is its output ?
count = 1;
while ( count<= 12)
{
cout << count << endl;
cout++;
}
If someone could explain this I would greatly appreciate it. Thank you !
Last edited on Feb 28, 2013 at 12:16pm Feb 28, 2013 at 12:16pm UTC
Feb 28, 2013 at 3:15pm Feb 28, 2013 at 3:15pm UTC
http://www.cplusplus.com/reference/ostream/ostream/
ostream has no operator++ defined.
Surely OP meant to write
count++;
Would this make more sense, OP:
for (int count = 1; count <= 12; count++)
?
The loop is going from count = 1 through 12. Or 1
to 13. Either way you word, it will fail on count = 13.
Count
1
2
3
4
5
6
7
8
9
10
11
12 <-- Last output.
13 <-- Fails here. Exits loop.
Last edited on Feb 28, 2013 at 9:01pm Feb 28, 2013 at 9:01pm UTC
Feb 28, 2013 at 5:43pm Feb 28, 2013 at 5:43pm UTC
Thanx for the help biscuit !
Feb 28, 2013 at 8:29pm Feb 28, 2013 at 8:29pm UTC
@ResidentBiscuit what would operator+ have to do with the post increment operator?