Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

way to initialize a boolean array in c99

Tags:

c

boolean

c99

What is the best way to initialize a boolean array in C99?

Maybe I can use this, I think.

bool f[5] = {false,};

Is this really okay?

If there is a better way, please let me know.

like image 953
H. Jang Avatar asked Sep 03 '26 17:09

H. Jang


1 Answers

If you want to initialize your array to "all false"/"all zeros" initial value, you can do

 bool f[5] = { false };

or you can do

 bool f[5] = { 0 };

Which variant is "the best" is for you to decide. There's no definitively "best" way here. Each one is as good as the other.

like image 168
AnT Avatar answered Sep 06 '26 09:09

AnT



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!