I am wondering how does int array[10]={0}
really work?
Does it go all the way through the entire array like this?
for(int i=0;i<10;i++) array[i]=0;
Or is it more efficient?
Depends on the scope of your variable.
array
will be placed in the .bss segment and zeroed before call to the main
function. Is it faster? It is definitely different as zeroing takes place before the main
start{0}
initialisation will be IMO faster as those internal routines are well optimised for the particular hardware. I have tested with gcc & VS and it is quicker - but of course there is no guarantee that your compiler will do it the same way. https://godbolt.org/g/JdTPHJ
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