char board[9]={0,1,2,3,4,5,6,7,8};
I know what the char board[9] is and does but what does {0,1,2,3,4,5,6,7,8} do i thought you can only give it one value
Printable View
char board[9]={0,1,2,3,4,5,6,7,8};
I know what the char board[9] is and does but what does {0,1,2,3,4,5,6,7,8} do i thought you can only give it one value
The {...} part is the initaliser list. It allows you to initialise all of the elements of the array at once. Thus, board[ 0 ] = 0, board[ 1 ] = 1, etc.
If there is just one number within the braces, then the whole array is filled with that number.
No. If there are less than N initializers, N being the size of the array, then all the rest are filled with zero.Quote:
Originally posted by XSquared
If there is just one number within the braces, then the whole array is filled with that number.
Quzah.
i see
char board [9] is an array of datatype 'character' which can store upto 9 alphabets(without spaces).Quote:
Originally posted by librab103
char board[9]={0,1,2,3,4,5,6,7,8};
I know what the char board[9] is and does but what does {0,1,2,3,4,5,6,7,8} do i thought you can only give it one value
Hence in your example, the variable board can store something like 'functions'.
Actually, it can only hold a word 8 letters long, because of the need for NULL-termination. But that's not the context it's being used in.
also keep in mind that it is illegal for an initializer to be completely empty or to be longer than the array it initializes!
cheers, Ben