You can initialize C++ array elements either one by one or using a single statement as follows:double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};The number of values between braces { } can not be larger than the number of elements that we declare for the array between square brackets [ ]. Following is an example to assign a single element of the array:If you omit the size of the array, an array just big enough to hold the initialization is created. Therefore, if you write:double balance[] = {1000.0, 2.0, 3.4, 17.0, 50.0};You will create exactly the same array as you did in the previous example.balance[4] = 50.0;The above statement assigns element number 5th in the array a value of 50.0. Array with 4th index will be 5th ie. last element because all arrays have 0 as the index of their first element which is also called base index. Following is the pictorial representaion of the same array we discussed above:
C++
Topic: Array
Explain about Initializing Arrays?
Browse random answers:
Explain about Declaring Arrays ?
Explain about Initializing Arrays?
Explain about Accessing Array Elements ?
What is the difference between an ARRAY and a LIST?
Define pointer and array. Explain the difference between them.
When should we use container classes instead of arrays?
What is Dynamic memory management for array?
What is the difference between class and objects?
What is static class member?
What are methods and fields?
What is an array?
What is a character array?
How do you decide which integer type to use?
Can you store multiple data types in System.Array?
Difference between "vector" and "array"?
How can double dimensional arrays be dynamically initialized in C++?
What is the difference between the System.Array.CopyTo() and System.Array.Clone()?
Why can't constant values be used to define an array's initial size?
What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
Delete duplicate elements from array
Is it valid to address one element beyond the end of an array?
Can the sizeof operator be used to tell the size of an array passed to a function?
What is meant by ?method-wars??
Write a program to delete an element from an array?