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
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.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
No. If there are less than N initializers, N being the size of the array, then all the rest are filled with zero.Originally posted by XSquared
If there is just one number within the braces, then the whole array is filled with that number.
Quzah.
Hope is the first step on the road to disappointment.
i see
char board [9] is an array of datatype 'character' which can store upto 9 alphabets(without spaces).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.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
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
Medical Robotics: "Pursuing perfection in healthcare through innovations in robotics and information technologies for medicine and surgery."