I have a very basic doubt. From the code below , I have declared Board[ ][ ] as a global char array. I would like to initialize the array in a function called init_board(). But the compiler returns
In function void init_board():
expected primary-expression before '{' token
expected ;' before '{' token
Code:
#include <iostream>
#include <conio.h>
using namespace std;
//global variables---------------
char Board[2][2];
//function declarations----------
void init_board();
int main(void)
{
init_board();
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<Board[i][j]<<" ";
}
cout<<"\n";
}
getch();
}
void init_board()
{
Board[2][2] = {{'a','b'},{'c','d'}};
}
What is the basic error I am making…please point out !!
Thanks
The initializer syntax can be used only while declaring the array, i.e.
In all other cases, you need to browse through the array elements and set them.