how can we get an array whose index will be start from 1 | Sololearn: Learn to code for FREE!

+1

how can we get an array whose index will be start from 1

Whenever you make a variable of arry type by default index starts from 0 but what is do that index starts from 1 ex by deafault a[3] having index 0 1 2 but accourding to my ques a[3] index will be 1 2 3

c dsa

11/27/2019 3:15:51 AM

Siddhant Jain

2 Answers

New Answer

+8

Just start from 1 Make array[0] be a null or irrelvant. And yes, make the array 1 size more than you want Problems: -You will have unused waste of space -More of a hassle Lua scripting language uses arrays starting from 1

+3

All arrays are 0 indexed so what you are trying is not possible but you can always access the element at any index given that the index is between 0 to arraySize - 1.