+ 1

Why compilation error?

#include <iostream> using namespace std; int main() { for(int d = 4; d > 1; d--) { d *= d; cout << d << endl; } cout << "D = " << d; }

13th Nov 2018, 12:23 PM
Igor The Golden Fish
Igor The Golden Fish - avatar
3 Réponses
+ 8
Another reason could be that variable d will never be less than or equal to 0 so it will run infinitely.
13th Nov 2018, 1:31 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
You tried to output d outside the for loop..that variable only exists within the loop's scope,Declare it outside the loop then your code will work.
13th Nov 2018, 12:30 PM
Mensch
Mensch - avatar
+ 1
Yes, it's true
13th Nov 2018, 12:31 PM
Igor The Golden Fish
Igor The Golden Fish - avatar