From bd8411405df21bd9cedf21b5963c9247cdfd0978 Mon Sep 17 00:00:00 2001 From: staerGazer <44284570+staerGazer@users.noreply.github.com> Date: Sat, 17 Nov 2018 11:44:53 -0500 Subject: [PATCH] added info on initializing arrays with fewer values than there are elements (#21814) I also stated that values are entered into an array in ascending order, starting with the first element. --- guide/english/cplusplus/arrays/index.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/guide/english/cplusplus/arrays/index.md b/guide/english/cplusplus/arrays/index.md index d373800c0a..264721099d 100644 --- a/guide/english/cplusplus/arrays/index.md +++ b/guide/english/cplusplus/arrays/index.md @@ -15,12 +15,18 @@ int numbers [5]; Initializiation: ```C++ -//Initialization with entries: +//Initialization with values: int numbers [5] = {1, 2, 3, 4, 5}; +//When initializing an array with values, the first value will be stored as the first element, the second value will be stored as the second element, ect... so the first element in this array is the value 1, and the third element is the value 3. //Initialization with no values: int numbers [5] = {}; +//Initialization with fewer values than elements: +int numbers [5] = {6}; +//Initializing an array with fewer values than there are elements will set the trailing elements to 0. +//int numbers [5] = {6} is equivalent to int numbers [5] = {6, 0, 0, 0, 0}; + //Initialization with declaration: int numbers [] = {1, 2, 3, 4, 5}; //Note that here the number of values defines the size of the array.