Array initialization | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Array initialization

Is there any way to make the index value of the first array entered as 1, instead of 0? I mean something which would make the address of first element of the array explicitly as 1,2,3.... so on instead of 0,1,2,3....

30th Sep 2017, 1:39 PM
Siraz Naorem
Siraz Naorem - avatar
9 Answers
+ 11
@Andrea That is actually pretty awesome. It's just that we'd never want to use it. :>
30th Sep 2017, 2:32 PM
Hatsy Rei
Hatsy Rei - avatar
+ 9
It is possible to get the user to input 1 and refer to the first element in the array, and so on, but for a programmer to type array[1] and expect the compiler to recognise it and refer to the first element in the array, I have not heard of any of such method.
30th Sep 2017, 1:54 PM
Hatsy Rei
Hatsy Rei - avatar
+ 8
I think that is not possible.
30th Sep 2017, 1:48 PM
Vukan
Vukan - avatar
+ 4
Something like this but...why? Tell me WHY? 😂😂😂 Yesss, I've done it! XD https://code.sololearn.com/cXlesHuLYJE9/?ref=app
30th Sep 2017, 2:24 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 2
I just think it will confuse your teammates to see that you use your own standard on array boundary, it's hard to cooperate when each we walk on our own paths. Just a thought :]
30th Sep 2017, 3:33 PM
Ipang
+ 1
I think it's possible by creating an array type using OOP and overloading operator []...maybe... Does it make sense for you? Does it make sense for someone?
30th Sep 2017, 2:01 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 1
@Hatsy that sounds like an alternate but then the size of array would be a problem. If I declare a 10 element array and point to the first one as default i would still lose the 0th element :/ hmmm... @Andrea didn't think of doing that yet....
30th Sep 2017, 2:21 PM
Siraz Naorem
Siraz Naorem - avatar
+ 1
Ahahah thanks @hatsy I dont care...code 4 fun :P
30th Sep 2017, 2:32 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
+ 1
Probably not really relevant but in lua the arrays start at 1 ^^. But then again they are not really arrays but tables.
30th Sep 2017, 3:01 PM
Dennis
Dennis - avatar