216k views
1 vote
If x is an int where x = 1, what will x be after the following loop terminates?

while (x < 100)

x *= 2;
A) 128
B) 2
C) 64
D) 100
E) none of the above; this is an infinite loop

User Tapy
by
8.3k points

1 Answer

3 votes

Final answer:

After the given loop terminates, the value of x will be 128.

Step-by-step explanation:

The given code snippet is a while loop that multiplies the value of x by 2 until x is no longer less than 100. Starting with x = 1, the loop will execute 7 times before terminating. Each time the loop runs, the value of x will double. So, after the loop terminates, x will be 2^7 = 128.

User Zorida
by
8.0k points