Ask Question
15 August, 20:57

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

+3
Answers (1)
  1. 15 August, 23:00
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers