Why Array Index starts from Zero
Answers were Sorted based on User's Feedback
Answer / manu
he compiler thinks that 0 is a positive number.
we have an integer range of
-128 to 127.
here -128 to -1 are negative numbers
and 0 to 127 are positive numbers
so array starts with the 0 as index.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rajesh bansal
This boils down to the concept of Binary digits. Take an
array size of 64 for example. We start from 0 and end at 63.
We require 6 bits.But, if we were to start from 1 and end at
64, we would require 7 bits to store the same number, thus
increasing the storage size......
For more details please check out this link...
http://www.mindstick.com/Interview/1100/Why%20Array%20Index%20starts%20from%20Zero
Thanks Everyone!!
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kamal
I think ther is need to give specific ans all the answer
looks complimentoy..
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / maragatham
because arrays are pointers and you are giving offsets from the base pointer
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rahul sharma
Dijkstra explains why we should index from 0. This is a
problem on how to denote a subsequence of natural numbers,
say for example 1,2,3,...,10. We have four solutions available:
a. 0<i<11
b. 1<=i<11
c. 0<i<=10
d. 1<=i<=10
Dijkstra argues that the proper notation should be able to
denote naturally the two following cases:
1. The subsequence includes the smallest natural number, 0
2. The subsequence is empty
Requirement 1. leaves out a. and c. since they would have
the form -1<i which uses a number not lying in the natural
number set (Dijkstra says this is ugly). So we are left with
b. and d. Now requirement 2. leaves out d. since for a set
including 0 that is shrunk to the empty one, d. takes the
form 0<=i<=-1, which is a little...well, messed up!
Subtracting the ranges in b. we also get the sequence
length, which is another plus. Hence we are left with b.
which is by far the most widely used notation in programming
now.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / lovely pal
i think array size [a+i] and [a+0] it is are both not possible beause if we add the any int in {a+i} ex-:i=1 and value is increse not possible at 0 state how can be possible[a+i] and[a+0].
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vishal kumar jaiswal
array name gives base address means internally it is pointer and also due to mapping concept like
arr[0]=
=*(arr+0)
=(500+0) // 500 is a base address
=*(500)
it gives first element otherwise it gives next element
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / krishnabhargav
This boils down to the concept of Binary digits. Take an
array size of 64 for example. We start from 0 and end at
63. We require 6 bits.But, if we were to start from 1 and
end at 64, we would require 7 bits to store the same
number, thus increasing the storage size.
| Is This Answer Correct ? | 12 Yes | 13 No |
Answer / kinshuk
All Answers are wrong. There are many programming languages
where array index starts from 1. Its all compiler specific
like Pascal
| Is This Answer Correct ? | 13 Yes | 14 No |
What is a critical section and how is it implemented?
how u can move CDC pointer to one line in cview?
If there is more than 100 control in a window how we can change the Taborder of a controls
What is the command routing in MFC framework?
if both base and derived class have the constructors if i create an object for derive class which class constructor is executed first
What is userdefine Messages in MFC?
Given two processes, how can they share memory?
What is the range of intensity of RGB
What is LPCTSTR? What does LP denote it?
What is CALLBACK? How it work? what is the advantage of CALLBACK, please explain with an example
WHAT IS DIFFERENT BETWEN RELEASE MODE & DEBUGGING MODE
4 Answers Google, Microsoft, TCS,
What are the types of button controls?