• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Array index start with zero?

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 91
Eclipse IDE Oracle Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

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

Why array index starts from zero
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27367
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a nasty piece of question-begging by Dijkstra, if that article is to be believed.
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Shiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic