Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize mulitdimensional C-array with 0 elements

How could I simple initialize a multidimensional C-array with 0 elements like this:

int a[2][2] = { { 0, 0 }, {0, 0} }
like image 532
multiholle Avatar asked Apr 08 '26 00:04

multiholle


2 Answers

This should work:

int a[2][2] = {0};

EDIT This trick may work for silencing the warning:

int a[2][2] = {{0}};
like image 124
Alexander Pogrebnyak Avatar answered Apr 10 '26 14:04

Alexander Pogrebnyak


Use memset:

memset(a,0,sizeof a);
like image 23
dcp Avatar answered Apr 10 '26 14:04

dcp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!