Q. What is the value of k after the following code fragment?~~~int k = 0;~~~int n = 12~~~while (k < n)~~~{~~~k = k + 1;~~~}
β
Correct Answer: (C)
12.
Explanation: You might wonder that how this value will be 12. Since k is initialised with 0 and n with 12.
Now while loop checks whether value of k is smaller than n or not. So this condition will be true unless te value of k becomes 11.
Now the value of k is 11 and the condition is true to while loop will be executed and now k will become 12.
So the final value of k will be 12.