Ask Question
6 September, 12:09

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. 6 September, 14:18
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers