Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array index start with zero?

 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Eclipse IDE Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Go through this link. It's interesting and will clear your doubt:

Why array index starts from zero
 
Henry Wong
author
Marshal
Pie
Posts: 20880
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Clapham
Sheriff
Pie
Posts: 20716
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a nasty piece of question-begging by Dijkstra, if that article is to be believed.
 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10084
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic