Error in codeblocks

+1 christopher Deacons · March 7, 2015

Hi there i'm following along with the c++ videos and i can't compile. am getting this error.

error: name lookup of 'x' changed for ISO 'for' scoping [-fpermissive]

i'm following buky's video about arrays no: 33


#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

int main (){

 int aray [9];

 cout << "Element  -  Value" << endl;

 for (int x = 0; x <=8; x++);
     aray[x] = 99;

      cout << x;
 return 0;

Post a Reply


Oldest  Newest  Rating
0 Dol Lod · March 7, 2015
You are including unecessary libraries. Both windows.h and strings.h are unecessary. 

If you declare variables within a for loop, they remain local to the for loop.

for(int i=0;i<9;i++)
// In this case i is declared to be local to the for loop

int i;

This version is legal because i is not local to the for loop and is instead part of the scope for the main function. Scoping refers to the outermost level at which the variable is declared. 
0 christopher Deacons · March 7, 2015
Ok that seems to work when the var is in the scope of main, that's strange i just followed as exactely as in buky's lesson.
0 christopher Deacons · March 7, 2015
"Both windows.h and strings.h are unecessary" after puting the variable in mains scope it worked and still with the 2 include files
+1 Abdullah Nauman · March 7, 2015
It will still work with extra libraries. But the more libraries you have. The longer it will take to compile/load your program.
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator