0
Can't create array such as arr[] : { a , b , c , d , e } ?
Is it not possible to create an array and variables that only have a name but no value at the same time like a , b , c , d , e ? Or do I have to write something such as: int arr[] : { arr[0] , arr[1] , arr[2] , arr[3] , arr[4] } every time?
7 Answers
+ 4
Fill in the blanks to define an array.
var
arr =
[
'A', 'B', 'C'
]
;
+ 2
This is possible in other languages through the use of keys, but not in C++ I'm afraid.
+ 1
Declare an array with your array's data type, followed by the name of your array, then followed by again with square brackets indicating the number of elements in your array.
int arr[5] = { 1, 2, 3, 4, 5 };
We are able to use the elements in an array by using it's index number, which ranges from 0 to (# of elements - 1). In our example, we can use arr[0] to arr[4].
std::cout << arr[3];
//output is 4.
0
the inly thing to do its to add var []
0
sorry i meant only
0
var
arr =
[
'A', 'B', 'C'
]
;
- 1
Yes Cohen Creber I understand this, I think. My question was probably asked clumsily.
What I'm asking is: is it not possible to name the elements in my array something like
a , b , c , d , e
Instead of having them named
arrayName[elementNumber]
Thanks!