Ask Question

What is the value of i after the following code is executed? int i = 1; while (i i) j--; i + = j; }

+5
Answers (1)
  1. 5 December, 20:49
    0
    The value of "i" after executing the entire code will be "16"

    Explanation:

    Initially the value of i will be 1. This value keeps changing after entering the while loop. Let me give you step by step result.

    When i = 1, it checks whether ii. so before the outer while loop ends "i" is reinitialized using "i=i+j".

    So When i = 1, the value of j after running inner while loop will be 1 and i will be reinitialized to 1+1 = 2, now i = 2

    So When i = 2, j = 2, Reinitialized value of i = 4

    So When i = 4, j = 4, Reinitialized value of i = 8

    So When i = 8, j = 8, Reinitialized value of i = 16.

    The loop will not get executed thereafter.

    You can add the below statement, after "j--; " to understand better.

    cout<<"i="<
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What is the value of i after the following code is executed? int i = 1; while (i i) j--; i + = j; } ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers