Question 4 (1 point) int x = 0; while (x > 10) { cout << x; x++; } What is the l
ID: 3896647 • Letter: Q
Question
Question 4 (1 point)
int x = 0;
while (x > 10) {
cout << x;
x++;
}
What is the last thing printed by the above code?
Question 4 options:
8
9
10
11
Nothing is printed
The code never ends
Save
Question 5 (1 point)
Which of the following symbols has the highest precedence?
Question 5 options:
++
||
&&
-
Save
Question 6 (1 point)
Which of the following code segments will count from 1 to 100 (including 1 and 100)?
Question 6 options:
for (int i=1; i<100; i++) {}
for (int i=1; i<100; ++i) {}
for (int i=0; i<=100; i++) {}
for (int i=0; i<=100; ++i) {}
for (int i=1; i<=100; ++i) {}
Save
Question 7 (1 point)
int x = 0;
while (x > 10) {
x++;
cout << x;
}
What is the first thing printed by the above code?
Question 7 options:
-1
0
1
2
Nothing is printed
Save
Question 8 (1 point)
If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition?
Question 8 options:
(2<=num<=5)
(2<5
(2 <= number && number <= 5)
(2 > number || number > 5)
(2 > number && number > 5)
(2 < number || number < 5)
(2 < number && number < 5)
(2 <= number || number <= 5)
Save
Question 9 (1 point)
int x;
for(x = 0;x > 0;x++) {
}
cout << x;
What is the last thing printed by the above code?
Question 9 options:
0
1
2
8
9
10
11
Nothing is printed
The code never ends
Save
Question 10 (1 point)
int x = 0;
while (x > 10) {
x++;
cout << x;
}
What is the last thing printed by the above code?
Question 10 options:
8
9
10
11
Nothing is printed
The code never ends
Save
Question 11 (1 point)
int x = 0;
while (x < 10) {
x++;
cout << x;
}
What is the last thing printed by the above code?
Question 11 options:
8
9
10
11
Nothing is printed
The code never ends
Save
Question 12 (1 point)
What is the value of x after the following code executes?
int x=10;
if ( ++x > 10 ) {
x=13;
}
Question 12 options:
10
9
13
11
Save
Question 13 (1 point)
If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test?
Question 13 options:
(x < 10 && y > 3)
(x >10 || y < 3)
(x >=10 && y <=3)
(x >=10 || y <=3)
Save
Question 14 (1 point)
int x;
for (x = 0; x < 10; x+=2) {
cout << x;
}
What is the output of the above code?
Question 14 options:
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
0 2 4 6 8
0 2 4 6 8 10
0 2 4 6 8 10 12
2 4 6 8
2 4 6 8 10
2 4 6 8 10 12
1 3 5 7 9
1 3 5 7 9 11
Nothing is printed
The code never ends
Save
Question 15 (1 point)
What is wrong with the following for loop?
for(int i=0;i<10;i--) {
cout << "Hello ";
}
Question 15 options:
can not use a for-loop for this
i is not initialized
infinite loop
off-by-one error
Save
Question 16 (1 point)
Which loop structure always executes at least once?
Question 16 options:
do-while
for
while
sentinel
Save
Question 17 (1 point)
Which of the following is not a good reason for choosing a certain loop control?
Question 17 options:
What the loop does
The minimum number of iterations of the loop
The condition for ending the loop
If the loop is in a function
Save
Question 18 (1 point)
int x;
for (x = 0; x < 10; ++x) {
++x;
cout << x;
}
What is the first thing printed by the above code?
Question 18 options:
-1
0
1
2
Nothing is printed
Save
Question 19 (1 point)
Question 19 options:
Complete the following code segment
// count from 1 to 100
// 1 is the first number printed
// 100 is the last number printed
int i=0;
while (i<100) {
cout << ____;
}
Save
Question 20 (1 point)
int x = 0;
while (x < 10) {
x++;
}
cout << x;
What is the last thing printed by the above code?
Question 20 options:
0
1
2
8
9
10
11
Nothing is printed
The code never ends
8
9
10
11
Nothing is printed
The code never ends
Explanation / Answer
Q4-
Nothing is printed because statring condition x>10 is false at the first iteration so it will not enter the loop and so nothing is printed.
Q5-
++ has the highest precedence.
Q6-for (int i=1; i<=100; ++i) {} will count from 1 to 100.
Q7- nothing is printed as x>10 is not true so it will not enter the loop.
Q8- (2 <= number || number <= 5) will ask user to enter number between 2 and 5 inclusive.
Q9-0 is printed because first x=0, so loop first condition is executed then x++ is done then it exits loop and prints x.
Q10- Nothing is printed because x never enter the loop.
Q11- last thing which is printed is 10.
Q12- value of x after execution will be 13 as ++x makes x=11 and 11>10 is true so x=13 is executed.
Q13-(x < 10 && y > 3) is the proper condition.
Q14-output will be 0 2 4 6 8 because loop ends at 9.
Q15-infinite loop as we are doing i-- so i will always decrease and the loop never terminates.
Q16-do-while loop executes atleast one time.
Q17-If the loop is in a function is not a good reason to choose a particular type of loop.
Q18-first thing that is printed is 1.
QQ20- 10 is printed at last by the code.
if you like the answer please provide a thumbs up.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.