# Multidimensinal arrays

 Syntax3rror Code · September 26, 2014 Can someone tell me why this ``void printBoard();    const int a = 3;   int test[a][a] = {{0,0,0},{0,0,0}};int main(){printBoard();    return 0;}void printBoard(){  for(int i = 0; i < a; i++){        for(int x = 0; x < a; x++){            cout << test[x];        }        cout << endl;   }}``will output: 000                  000                  000But this ``void printBoard();    const int a = 3;   char test[a][a] = {{'x','x','x'},{'x','x','x'}};int main(){printBoard();    return 0;}void printBoard(){  for(int i = 0; i < a; i++){        for(int x = 0; x < a; x++){            cout << test[x];        }        cout << endl;   }}``outputs : xxx               xxxI know the first one is int the second one is char but i just dont understand why the second one doesnt print   xxx                                                                                                                                                                               xxx                                                                                                                                                                               xxxand how do i print xxx                             xxx                             xxx

## Replies

 Franz Schmidt · September 26, 2014 I don't even know how you get000000000 with just test[x].If I compile your code I get this:If you want to print every element of the matrix you need to use the output like a matrix:``void printBoard(){ for (int n = 0; n < a; n++){ for (int x = 0; x < a; x++){ cout << test[n][x]; } cout << endl; }}``Than also the other code with the char array will work (but just with two lines!)I hope you intended not to fill your complete array...The reason why the int output has 3 lines is, that if you don't declair a part of your array it gets automatical filled with 0 (just integer).But if you have a char array the array doesn't get filled with a value (or just filled with '\0') and you can't print those linesEDIT: Sorry didn't recognized buckysroom has a bug and doesn't show
• 1

## C++

130,868 followers