Bogdan Alexandru
Bogdan Alexandru

Reputation: 5542

Can I initialize an array of array with all 0s?

I have this:

uint8_t buf[X][Y];

I would like to initialize all elements to 0. Will this do the trick:

uint8_t buf[X][Y] = { 0 };

? i.e. will it initialize all X*Y elements to 0?

Upvotes: 1

Views: 270

Answers (1)

Timbo
Timbo

Reputation: 28050

Yes. If you have an initializer ({ ... }), all elements not explicitly initialized will be initialized to zero.

Edit: Removed part that is not correct when using C.

Upvotes: 2

Related Questions