Take the 2-minute tour ×

Possible Duplicate:
What is the meaning of double curly braces initializing a C-struct ?

for this following structure,

typedef struct matrix
    float data[16];
} matrix;

Is there any difference between,

matrix test1 = {0};


matrix test1 = { { 0 } };

when it comes to initializing the data member of the structure. Both initializes data to zero.

Some insight when it comes to C or C++, would be great.

share|improve this question

marked as duplicate by Björn Pollex, Ólafur Waage, cnicutar, Alok Save, Ferdinand Beyer Jun 28 '11 at 8:30


There is no partial initialization in C. An object either isn't initialized at all, or it is fully initialized. {0} explicitly initializes the first member to 0 and implicitly initializes (to 0) all other members. –  pmg Jun 28 '11 at 9:02

1 Answer 1

up vote 1 down vote accepted

With matrix test1 = { 0 } you will initialize test1 with all zero's and with matrix test1 = { { 0 } } You will initialize test1.data. with all zero's in this case it does the same actually since you don't have any other data definitions in your struct :)

share|improve this answer
That means, if I had another member in the struct then, using { { 0 } } wouldn't initialize the second variable as zero? But, that doesn't happen, however I use single or double, all are being initialized with zero! –  iamcreasy Jun 28 '11 at 8:36
