+ 1

Why does an int pass a value when defined outside the main() function, but not inside for a for loop?

this works #include <iostream> using namespace std; int a; int main() { for (a; a < 10; a++) { cout << a << endl; } return 0; } but this doesnt #include <iostream> using namespace std; int main() { int a; for (a; a < 10; a++) { cout << a << endl; } return 0; }

1st Jan 2017, 8:53 PM
Zachery Mills
Zachery Mills - avatar
3 Antworten
+ 6
The loop condition should be writen: (; a < 10; a++) (try removing the initial "a")
2nd Jan 2017, 9:27 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
When inside it's "local" and only the parent can access it.
1st Jan 2017, 8:56 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
yes but shouldn't all of the data that is local to the same function be able to be accessed in side that function?
1st Jan 2017, 9:04 PM
Zachery Mills
Zachery Mills - avatar