|
|
 | | From: | masood.iqbal at lycos.com | | Subject: | Multi-dimensional array initialization | | Date: | 23 Jan 2005 00:52:08 -0800 |
|
|
 | Hi,
I have seen at least two ways to initialize multi-dimensional arrays in C. One of the ways is shown in a sample code snippet below. The other way does not make use of any intermediate braces. In other words, all the entries are listed under the same pair of enclosing braces. For example:
char* mdTbl[3][5] = { "One", "Two", "Three", "Four","Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen" };
Are the two approaches exactly identical, or is there any difference between them?
Thanks, Masood /****************************************************** ******************************************************/
#include
char* mdTbl[3][5] = { { "One", "Two", "Three", "Four", "Five" }, { "Six", "Seven", "Eight", "Nine", "Ten" }, { "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen" }, };
void print_array_element(int row, int column) { printf("%s\n", mdTbl[row][column]); }
main() { print_array_element(2, 2); }
|
|
 | | From: | masood.iqbal at lycos.com | | Subject: | Re: Multi-dimensional array initialization | | Date: | 23 Jan 2005 05:51:10 -0800 |
|
|
 | Hi,
I have seen at least two ways to initialize multi-dimensional arrays in C. One of the ways is shown in a sample code snippet below. The other way does not make use of any intermediate braces. In other words, all the entries are listed under the same pair of enclosing braces. For example:
char* mdTbl[3][5] = { "One", "Two", "Three", "Four","Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen" };
Are the two approaches exactly identical, or is there any difference between them?
Thanks, Masood /****************************************************** ******************************************************/
#include
char* mdTbl[3][5] = { { "One", "Two", "Three", "Four", "Five" },
{ "Six", "Seven", "Eight", "Nine", "Ten" },
{ "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen"
}, };
void print_array_element(int row, int column) { printf("%s\n", mdTbl[row][column]); }
main() { print_array_element(2, 2); }
|
|
 | | From: | pete | | Subject: | Re: Multi-dimensional array initialization | | Date: | Sun, 23 Jan 2005 10:19:05 GMT |
|
|
 | masood.iqbal@lycos.com wrote: > > Hi, > > I have seen at least two ways to > initialize multi-dimensional arrays in C. > One of the ways is shown in a sample code snippet below. The other > way does not make use of any intermediate braces. In other words, all > the entries are listed under the same pair of enclosing braces. For > example: > > char* mdTbl[3][5] = { "One", "Two", "Three", "Four","Five", "Six", > "Seven", > "Eight", "Nine", "Ten", "Eleven", "Twelve", > "Thirteen", > "Fourteen", "Fifteen" }; > > Are the two approaches exactly identical,
Yes. The left most brackets may be left empty in an array initialization.
char* mdTbl[][5] = { "One", "Two", "Three", "Four","Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen","Fourteen", "Fifteen" };
-- pete
|
|
|