Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array doesn't initialize with a curly braces in c++

Tags:

c++

arrays

I'm learning c++ and I've encountered the following strange thing:

If I initialize array like the book says

int my_array[5] = {10}

every array field is still initialized to zero, when it should be ten.

If I initialize it in a loop, it works as intended

What is happening? I'm using Ubuntu and compiling with g++

like image 374
Marko Kacanski Avatar asked Nov 29 '22 00:11

Marko Kacanski


1 Answers

What you observe is correct: the remaining items of the array are initialized to 0, according to the standard.

like image 166
Jarhmander Avatar answered Dec 20 '22 09:12

Jarhmander