+ 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....
9 Respostas
+ 11
@Andrea That is actually pretty awesome. It's just that we'd never want to use it. :>
+ 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.
+ 8
I think that is not possible.
+ 4
Something like this but...why?
Tell me WHY? 😂😂😂
Yesss, I've done it! XD
https://code.sololearn.com/cXlesHuLYJE9/?ref=app
+ 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 :]
+ 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?
+ 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....
+ 1
Ahahah thanks @hatsy
I dont care...code 4 fun :P
+ 1
Probably not really relevant but in lua the arrays start at 1 ^^.
But then again they are not really arrays but tables.