GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 59 of 209    Print  
why array index starts from 0[zero] only?

  
Total Answers and Comments: 6 Last Update: February 01, 2009     Asked by: rajesh 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: bsamar
 
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.

Above answer was rated as good by the following members:
wael.salman, newlife
December 13, 2005 03:49:08   
sarika        

RE: why array index starts from 0[zero] only?
c C++ compilers are build such that.so array index always starts with 0.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
December 21, 2005 05:22:29   
bsamar Member Since: December 2005   Contribution: 2    

RE: why array index starts from 0[zero] only?
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 useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
January 12, 2006 09:48:36   
sandya_nath Member Since: January 2006   Contribution: 1    

RE: why array index starts from 0[zero] only?

Array starts with zero because for the easy manipulation start from the whole numbers.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 07, 2006 00:31:54   
neeraj_sathe Member Since: April 2006   Contribution: 1    

RE: why array index starts from 0[zero] only?
amarnath B.S. has explained the concept properly I would like to know the mechanism that he has described in detail.
 
Is this answer useful? Yes | No
August 24, 2006 01:49:14   
Vincent        

RE: why array index starts from 0[zero] only?
because the name of an array is actually a pointer to the first element of this array in memory :array[0] is equivalent to *arrayarray[1] is equivalent to *(array + 1)...array[i] is equivalent to *(array + i)
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
January 30, 2009 02:48:08   
Nisikant Member Since: January 2009   Contribution: 8    

RE: why array index starts from 0[zero] only?

The array is terminated by a NULL character. Hence for array elements the space will be length-1. suppose you have 5 elements in an array. The last position is occupied by NULL character then space available is 4. If the index will start from 1 then how can one store 5 elements. To over come this problems the array index starts from zero(0). It is a prorgamming technique of a programming language.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape