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?

2nd Nov 2016, 9:07 PM
Deneroth Eisenhorn
Deneroth Eisenhorn - avatar
7 odpowiedzi
+ 4
Fill in the blanks to define an array. var arr = [ 'A', 'B', 'C' ] ;
13th Jun 2019, 1:44 AM
Daniel Nehema
Daniel Nehema - avatar
+ 2
This is possible in other languages through the use of keys, but not in C++ I'm afraid.
3rd Nov 2016, 11:02 AM
Cohen Creber
Cohen Creber - avatar
+ 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.
3rd Nov 2016, 12:41 AM
Cohen Creber
Cohen Creber - avatar
0
the inly thing to do its to add var []
16th Aug 2020, 9:22 PM
omo daniel
omo daniel - avatar
0
sorry i meant only
16th Aug 2020, 9:23 PM
omo daniel
omo daniel - avatar
0
var arr = [ 'A', 'B', 'C' ] ;
9th Aug 2021, 2:28 PM
Owethu Sotomela
Owethu Sotomela - avatar
- 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!
3rd Nov 2016, 6:14 AM
Deneroth Eisenhorn
Deneroth Eisenhorn - avatar