Why compilation error? | Sololearn: Learn to code for FREE!

+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; }

11/13/2018 12:23:16 PM

Igor The Golden Fish

3 Answers

New Answer

+8

Another reason could be that variable d will never be less than or equal to 0 so it will run infinitely.

+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.

+1

Yes, it's true