+ 1
For loop outputs
I am pondering about the output for the following two sets of code: 1) #include <iostream> using namespace std; int main() { for (int a = 10; a >= 0; a -= 3) { cout << a << endl; } return 0; } 2) #include <iostream> using namespace std; int main() { int x; for(x=0; x<4; ++x) { } cout<< x << endl; } The former one, as expected, prints out: 10 7 4 1 The latter one, however, only prints out: 4 Why won't the latter code print the following? 0 1 2 3
4 Respostas
+ 3
Add cout << x << endl; inside the for-loop body, it is currently empty.
+ 2
Relax bro BTDT 😁
+ 1
*facepalms*