| Author |
Array index start with zero?
|
Ritesh raushan
Ranch Hand
Joined: Aug 29, 2012
Posts: 97
|
|
|
Why array index start with zero in c,cpp,java but in cobol,fortron start with index 1.....please help me this my interview question and i did'nt get select..
|
 |
Komal Arora
Ranch Hand
Joined: Sep 30, 2010
Posts: 91
|
|
Hey,
Go through this link. It's interesting and will clear your doubt:
Why array index starts from zero
|
OCPJP
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16684
|
|
Ritesh raushan wrote:Why array index start with zero in c,cpp,java but in cobol,fortron start with index 1.....please help me this my interview question and i did'nt get select..
Quite frankly. I would have challenged back -- as the answer to why, for all those languages, can only lowest common denominator to "because that is how it is designed". Even the article presented, which I don't completely agree with, doesn't explain why fortran starts with one.
And of course, a plug for one of my favorite languages, Pascal -- in that language, you specify the range, so you can have it start with zero, one, or anything, that matches your algorithm.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
That's a nasty piece of question-begging by Dijkstra, if that article is to be believed.
|
 |
Steve Fahlbusch
Ranch Hand
Joined: Sep 18, 2000
Posts: 491
|
|
Sorry Henry - at least to me pascal sucks - any language that by design exits out with any error is just plain stupid to me.
Now why FORTRAN and COBOL and even Algol had 1 as the starting infix was that they were created for math/ business folks.
PL/1was the first language that had both variable I dices and no reserved words.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4739
|
|
Steve Fahlbusch wrote:PL/1was the first language that had both variable I dices and no reserved words.
And the verify() method - sadly forgotten now it seems. Wonderful function.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
 |
|
|
subject: Array index start with zero?
|
|
|