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 |
1)dynamic creation of a Button ?
what is message Testing ?
What is stack size in win32 program?
Difference between Cclint DC & Cpaint Dc
what is the component of CLR ?
What is the difference between Struts and JSF? Pls list some most suitable differences.
how many types of classes are ther,what are that
Why not virtual functions to handle messages?
Types of DLL's
What is the difference between hinsrtance and hprevinstance in WinMain function?
What is the difference between the Encapsulation and Abstraction
25 Answers HCL, Invensys, TCS, Wipro,
What view class enables you to use an edit control as a view?