I am going through some C codes. Some of them are a little difficult to understand. For instance, what does following assignment do:
MY_TYPE my_var[3]={0};
MY_TYPE
is some fixed point arithmetic type. I have not yet come across variables with []
brackets and assignment with {}
around values.
That was too easy, I guess. So, what's advantage of defining
my_type my_var[3]={0};
over this:
my_type my_var[3];
It creates an array my_var
of type MY_TYPE
that is of size 3 and is initialised to all 0s (I suspect MY_TYPE
is some sort of integer type). Note that only one initialisation is necessary for the rest to be init`ed too.
Also note that if you declare the array globally as opposed to within a block, then it will be initialised automatically and this MY_TYPE my_var[3];
will be enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With