Output of this code snippet?

What is the output of the following code?

int x = 0;
int i;
for (i = 0; i < 4; i++) ;
x++;
if (x == 3)
cout << "*";
I believe it is just *, but can someone confirm?
Thanks,
You could try actually compiling it to see for yourself. =P
Actually, as it stands, there will be no output. If you click on the little "cog wheel" icon at the top right corner of the code below you can see for yourself!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

int main() {
cout << "begin main()\n";

int x = 0;
int i;
for (i = 0; i < 4; i++) ;
x++;
if (x == 3)
cout << "*";

cout << "end main()\n";
return 0;
}


You could even add a few more output lines to help you follow the program flow?

Andy

PS "How to use code tags"
http://www.cplusplus.com/articles/jEywvCM9/


Last edited on
Topic archived. No new replies allowed.