intmyNum[3] = {10,20,30}; Access the Elements of an Array You access an array element by referring to the index number inside square brackets[]. This statement accesses the value of thefirst elementincars: Example string cars[4] = {"Volvo","BMW","Ford","Mazda"}; ...
Each set of square brackets in an array declaration adds another dimension to an array. An array like the one above is said to have two dimensions.Arrays can have any number of dimensions. The more dimensions an array has, the more complex the code becomes. The following array has three ...
for(intage : ages) { sum += age; } // Calculate the average by dividing the sum by the length avg = sum /length; // Print the average cout <<"The average age is: "<< avg<<"\n"; Try it Yourself » And in this example, we create a program that finds the lowest age among...
The number of elements in the array The size of the array in bytes The last element of the array The sum of all elements in the arraySubmit Answer » What is an Exercise? Test what you learned in the chapter: C++ Get Array Size by completing 5 relevant exercises. To try more C++...
YesNo Next Exercise » What happens if you omit the size of an array when declaring it with initial values? The compiler determines the array size based on the number of values provided An error occurs The array has a size of 0