• Amazon: You are probably the master of C, if you can answer this beginner level question

    Why we use inclusive lower bond and exclusive upper bond for array?
    confused?

    i.e why we see this syntax

    int a[10];
    for(i=0;i<10;i++)


    instead of

    int a[10];
    for(i=0;i<=9;i++)


    Being faithful to your inner soul, If you don't know the answer, join our site and subscribe for latest updates.

    And don't forget to ask the answer of this question.

8 comments:

  1. Unknown said...

    int a[10];
    for(i=0;i<10;i++)
    uses single comparison

    int a[10];
    for(i=0;i<=9;i++)
    uses double comparison

  2. Unknown said...

    Not exactly!!!!!
    This is not the reason!!

  3. selvakumar said...

    i can`t get your question.
    but anyway both inputs 10 values and stores in the array.

  4. Unknown said...

    See buddy in first example it is i<10 and in 2nd i<=9
    in most of the books u'll find the syntax in 1st format but in 2nd what is the reason for that?

  5. tapas said...

    according to me in books its written i<10 to show the students the size is 10 and the array starts from 0... so array have 10 elements..i dont think there is any huge concept behind that...

  6. Unknown said...

    Ya you are right partially.

    i=1,i<=9,i++
    for eg. if there is a string having 70 characters.
    if we take a substring starting from 9 and ending at 29.
    Then one could guess it has 20 characters. but actually it has 21 characters.
    That's why it is a standard to include lower index and exclude upper index.

    Hope you got what I am trying to say. :)

  7. tapas said...

    ya ...actually i was saying the same but couldnt explain much clearly as u did...

  8. Unknown said...

    Its ok buddy.
    but anyways well attempt!!
    Interviewer asks such type of questions!!

Post a Comment