+ 3

Why this code is showing an error? Pls. Help

But after removing the semicolon ; from the end of the for loop it has no error why so? #include <iostream> using namespace std; int main() { for(int i=0;i<7;i++); cout<<i; return 0; }

1st May 2017, 6:09 AM
Vineet Mishra
Vineet Mishra - avatar
2 Respuestas
+ 9
Because you have declared i inside for loop and is not accessible outside the scope of that for loop. Correct code. #include <iostream> using namespace std; int main() { int i; for(i=0;i<7;i++); cout<<i; return 0; }
1st May 2017, 6:14 AM
Ashwani Kumar
Ashwani Kumar - avatar
+ 1
the for loop doesn't have a semicolon at the end
1st May 2017, 8:46 PM
Bil Al
Bil Al - avatar