<p>You are starting with a base memory address and you are adding an offset having the size of one array element for each following element. This makes address calculation very easy (base address + n * size of data structure). </p>

<p>Negative indexes are not allowed because you would refer to the memory address in front of your base address, which means you might destroy other variables content.</p>

CC BY-SA 4.0
2018-10-29T19:51:28.357Z
Re, "...this makes address calculation very easy..." That is a reason why arrays can be more efficiently implemented if the range of allowed indices is contiguous, but it does not explain why that range should not include any negative numbers.
Solomon Slow
CC BY-SA 4.0
2018-10-29T19:51:39.343Z
Re, "...you might destroy other variable's content."  That is a reason why you should not use out-of-bounds array indices, but it does not explain why negative numbers should be out-of-bounds.
Solomon Slow
CC BY-SA 4.0
2018-10-29T20:01:12.527Z
There is no _strong_ reason why negative numbers typically are not allowed.  Probably the best reason is, Many languages, for simplicity's sake, only allow the programmer to specify the size of an array, rather than allowing the programmer to specify a starting and ending index. If you want to choose one starting index that will make everybody happy, there are not very many reasonable choices.  Some programmers will grumble if you choose 0.  Some will grumble if you choose 1.  _Everybody_ will grumble (and, nobody will use your language) if you choose any other number.
Solomon Slow
CC BY-SA 4.0
2018-10-31T12:14:08.547Z
Consider "The principle of least surprise". Or, minimum grumbling. Maybe negative indices would refer to imaginary data? Probably appropriate for quantum computing.
Scott Rowe
CC BY-SA 4.0
2018-10-26T20:51:03.907Z
2019-06-09T12:55:19.053Z
2019-06-09T12:55:19.053Z
OBu
<p>Arrays start from 0 then 1,2... But why are indexes positive, why are indexes not negative? </p>

CC BY-SA 4.0
2018-10-27T00:44:48.387Z
In some languages you can index of lots of thing, including a range of negatives or an enumeration type.
Buffy
CC BY-SA 4.0
2018-10-27T03:35:19.307Z
Okk but I try to gave negavtive index in c++ then its show error.is this an other way to gave negative index ??
Iram Shah
CC BY-SA 4.0
2018-10-27T18:43:18.683Z
What are you trying to achieve with the negative index?
OBu
CC BY-SA 4.0
2018-10-27T20:21:55.863Z
I am a student and all teachers tell us only about positive index in array. So there is a question in my mind that is it possible to gave negative index if yes the. How is it possible
Iram Shah
CC BY-SA 4.0
2018-10-28T02:17:21.920Z
In COBOL, array indexes start at 1. Then the compiler, under the covers, converts the index to a zero based offset from a base pointer.
pojo-guy
CC BY-SA 4.0
2018-10-28T03:46:16.313Z
So its mean if I want to gave negative index number that start from -1 then firstly I should set compiler as I want ??
Iram Shah
CC BY-SA 4.0
2018-10-28T12:42:51.800Z
it means it's up to the language to decide what the index number really means. E.g. in python, lists can have an index like my_list[-1] - which is the last element in the list.
OBu
CC BY-SA 4.0
2018-10-28T18:22:51.460Z
Hi @IramShah, welcome to [cseducators.se]! I'm afraid that I had to close this question, as it is off-topic for the site. CSEd is mostly for teachers, and it is about how to teach CS concepts. So a question about classroom practice would be topical here. However, I see that you already received a good answer, so I hope that you also got the help that you need!
Ben I.
CC BY-SA 4.0
2018-10-28T19:20:50.457Z
Ok.............
Iram Shah
CC BY-SA 4.0
2018-10-31T17:40:27.260Z
“Everything has to start somewhere”: if it starts at zero, then it can not start at a negative number, in the same way that it can not start at 42 (because it starts at zero).
ctrl-alt-delor
<arrays>
Why does array index not start from -1 why have indexes to be positive?
# Why does array index not start from -1 why have indexes to be positive?

(Asked by: username_0 on 2018-10-26)

Arrays start from 0 then 1,2... But why are indexes positive, why are indexes not negative?

**Tags:** arrays

> **Comments:**
> **username_1**: In some languages you can index of lots of thing, including a range of negatives or an enumeration type.  
> **username_0**: Okk but I try to gave negavtive index in c++ then its show error.is this an other way to gave negative index ??  
> **username_2**: What are you trying to achieve with the negative index?  
> **username_0**: I am a student and all teachers tell us only about positive index in array. So there is a question in my mind that is it possible to gave negative index if yes the. How is it possible  
> **username_3**: In COBOL, array indexes start at 1. Then the compiler, under the covers, converts the index to a zero based offset from a base pointer.  
> **username_0**: So its mean if I want to gave negative index number that start from -1 then firstly I should set compiler as I want ??  
> **username_2**: it means it's up to the language to decide what the index number really means. E.g. in python, lists can have an index like my_list[-1] - which is the last element in the list.  
> **username_4**: Hi @IramShah, welcome to [cseducators.se]! I'm afraid that I had to close this question, as it is off-topic for the site. CSEd is mostly for teachers, and it is about how to teach CS concepts. So a question about classroom practice would be topical here. However, I see that you already received a good answer, so I hope that you also got the help that you need!  
> **username_0**: Ok.............  
> **username_5**: “Everything has to start somewhere”: if it starts at zero, then it can not start at a negative number, in the same way that it can not start at 42 (because it starts at zero).  

---

## 1 answers

### Answer by username_2 on 2018-10-26. Score: 4 | Accepted answer

You are starting with a base memory address and you are adding an offset having the size of one array element for each following element. This makes address calculation very easy (base address + n \* size of data structure).

Negative indexes are not allowed because you would refer to the memory address in front of your base address, which means you might destroy other variables content.

> **Comments:**
> **username_6**: Re, "...this makes address calculation very easy..." That is a reason why arrays can be more efficiently implemented if the range of allowed indices is contiguous, but it does not explain why that range should not include any negative numbers.  
> **username_6**: Re, "...you might destroy other variable's content."  That is a reason why you should not use out-of-bounds array indices, but it does not explain why negative numbers should be out-of-bounds.  
> **username_6**: There is no _strong_ reason why negative numbers typically are not allowed.  Probably the best reason is, Many languages, for simplicity's sake, only allow the programmer to specify the size of an array, rather than allowing the programmer to specify a starting and ending index. If you want to choose one starting index that will make everybody happy, there are not very many reasonable choices.  Some programmers will grumble if you choose 0.  Some will grumble if you choose 1.  _Everybody_ will grumble (and, nobody will use your language) if you choose any other number.  
> **username_7**: Consider "The principle of least surprise". Or, minimum grumbling. Maybe negative indices would refer to imaginary data? Probably appropriate for quantum computing.  

---

