File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array index start with zero? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array index start with zero?" Watch "Array index start with zero?" New topic
Author

Array index start with zero?

Ritesh raushan
Ranch Hand

Joined: Aug 29, 2012
Posts: 100
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: 18978
    
  40

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: 18886
    
    8

That's a nasty piece of question-begging by Dijkstra, if that article is to be believed.
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 581
    
    7

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: 8196
    
  23

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?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array index start with zero?