Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-29T19:51:28.357Z
Answers.Text: 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.
Answers.UserDisplayName: Solomon Slow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-29T19:51:39.343Z
Answers.Text: 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.
Answers.UserDisplayName: Solomon Slow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-29T20:01:12.527Z
Answers.Text: 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.
Answers.UserDisplayName: Solomon Slow
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-31T12:14:08.547Z
Answers.Text: Consider "The principle of least surprise". Or, minimum grumbling. Maybe negative indices would refer to imaginary data? Probably appropriate for quantum computing.
Answers.UserDisplayName: Scott Rowe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-26T20:51:03.907Z
Answers.LastActivityDate: 2019-06-09T12:55:19.053Z
Answers.LastEditDate: 2019-06-09T12:55:19.053Z
Answers.UserDisplayName: OBu
Body: <p>Arrays start from 0 then 1,2... But why are indexes positive, why are indexes not negative? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-27T00:44:48.387Z
Comments.Text: In some languages you can index of lots of thing, including a range of negatives or an enumeration type.
Comments.UserDisplayName: Buffy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-27T03:35:19.307Z
Comments.Text: Okk but I try to gave negavtive index in c++ then its show error.is this an other way to gave negative index ??
Comments.UserDisplayName: Iram Shah
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-27T18:43:18.683Z
Comments.Text: What are you trying to achieve with the negative index?
Comments.UserDisplayName: OBu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-27T20:21:55.863Z
Comments.Text: 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
Comments.UserDisplayName: Iram Shah
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-28T02:17:21.920Z
Comments.Text: 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.
Comments.UserDisplayName: pojo-guy
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-28T03:46:16.313Z
Comments.Text: So its mean if I want to gave negative index number that start from -1 then firstly I should set compiler as I want ??
Comments.UserDisplayName: Iram Shah
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-28T12:42:51.800Z
Comments.Text: 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.
Comments.UserDisplayName: OBu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-28T18:22:51.460Z
Comments.Text: 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!
Comments.UserDisplayName: Ben I.
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-28T19:20:50.457Z
Comments.Text: Ok.............
Comments.UserDisplayName: Iram Shah
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-31T17:40:27.260Z
Comments.Text: “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).
Comments.UserDisplayName: ctrl-alt-delor
Tags: <arrays>
Title: Why does array index not start from -1 why have indexes to be positive?
ThreadText: # 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 @username_0, 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.  
  
  ---
  
  