C++

Asked • 07/28/19

Initialization of a normal array with one default value?

[C++ Notes: Array Initialization](http://www.fredosaurus.com/notes-cpp/arrayptr/array-initialization.html) has a nice list over initialization of arrays. I have a int array[100] = {-1};expecting it to be full with -1's but its not, only first value is and the rest are 0's mixed with random values.The code int array[100] = {0};works just fine and sets each element to 0.What am I missing here.. Can't one initialize it if the value isn't zero ?2: Is the default initialization (as above ) faster than the usual loop through the whole array and assign a value or does it do the same thing?

1 Expert Answer

By:

Sasi T. answered • 07/30/19

Tutor
New to Wyzant

I love to learn and spread knowledge!

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.