0
Why no output?
#include <iostream> using namespace std; int main() { #define root = 40; for(int x = root, k = 0; x > 0, k > 0; x/=10, k++) { cout << k << endl; } return 0; }
4 Answers
+ 4
#include <iostream>
#define root 40;
using namespace std;
int main()
{
int k;
for(int x = root;k = 0,x > 0, k > 0, x/=10, k++)
{
cout << k << endl;
}
return 0;
}
+ 2
I suggest you to read here https://en.cppreference.com/w/cpp/language/for
+ 1
k = 0 isn't condition
+ 1
The body of your for loop will be executed as long as âx > 0â and âk > 0â are true.
But initially k = 0, so the condition âk > 0â is false and the loop is exited.