Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

03225186213

  • 3 years ago

a[]={0,1,2,3,4,5,6,7,8,9,10}; i=0; a[i]=a[++i+a[++i]]+a[++i]; cout<<a[i]; ans 9 whats the logic?

  • This Question is Closed
  1. Matrix65
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    cout<<a[9]; //if u output 9

  2. 03225186213
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    ans is 9

  3. Matrix65
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yes,

  4. 03225186213
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i know ans is 9 how it came(evaluated)?

  5. jon.stromer.galley
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    This is a test of your understanding of order of operations. At std::cout you should see that i == 3. What is a[ 3 + a[3]] + a[3]?

  6. 03225186213
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i evaluated like a[1+a[2]]+a[3]; tell me the logic of 3 at all places

  7. jon.stromer.galley
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    ++i is evaluated first, so the function is: a[ 3 + a[3]] + a[3] not a[1+a[2]]+a[3] thus a[ 3 + a[3]] + a[3] == a[3 +3] + 3 == a[6] + 3 == 6 + 3 == 9

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy