Thursday, July 9, 2009

How to initialise a 2D array in C++?

Hello,





How do I initialise a global 2D arary in C++?





First, I declared the 2D array outside of the main function.


int data[32][5];





Then in the main function, I initialized the array:





data[32][5] = {{0,0,0,0,0},


{0,0,0,0,1},{0,0,0,1,0},{0,0,0,1,1},{0...


......................................... integers here)..........


{1,1,1,1,1}};





The above is what I typed into visual c++ 2005. After the comma of every 5th bracket, I pressed 'Enter' to go to a new line.





However, when I compiled, there were syntax errors saying that there are missing ; before '{' or '}' .





What is the syntax error?

How to initialise a 2D array in C++?
is your declaration is correct


it should be defined as:





public int data[][];


public int main()


{


data[32][5]={{.......}{.......}{.........


}


No comments:

Post a Comment