TopBottom

Followers



Click on more
SUBSCRIBE

Enter your email address:

Delivered by FeedBurner



VIDEO

Announcement: wanna exchange links? contact me at ravikrak@yahoo.com

Initialization Of Two-Dimentional Arrays

Posted by Ravi Kumar at Sunday, September 18, 2011
Share this post:
Ma.gnolia DiggIt! Del.icio.us Yahoo Furl Technorati Reddit

like the one-dimensional arrays,two-dimensional arrays
may be initialized by following their declaration with a
list of initial values enclosed in braces.
for example,
static int table[2][3] = {0,0,0,1,1,1};
initializes the elements of the first row to zero and
the second row to one.The initialization is done row by row.
The above statement can be equivalently written as
static int table[2][3]={{0,0,0}, {1,1,1});
by surrounding the elements of each row by braces.

we can also initialize a two-dimensional array in the
form of a matrix as shown below:
static int table[2][3] = { {0,0,0},
{1,1,1}
};
note the syntax of the above statements, commas are required
after each brace that closes off a row, except in the case of
the last row.If the values are missing in an initializer,they
are automatically set to zero. For instance, the statement

static int table[2][3] = {
{1,1},
{2}
};
will initialize the first two elements of the first row to
one, the first element of the second row to two, and other
elements to zero.When all the elements are to be initialized to
zero, the following short-cut method may be used.
Static int m[3][4]= {{0}, {0}, {0},{0}};
the first element of each row is explicitly initialized to
zero while other elements are automatically initializes to zero.

Share |

Labels:

0 comments:

Post a Comment