Complete Solutions 100% Verified 2025
1.
What is the output from the following fragment?z = 15 ;while (z <= 20) z = z + 2 ;cout << z <<
endl ;
A.
15
B.
17
C.
19
D.
20
,E.
21
Correct Answer
E. 21
Explanation
The code initializes the variable z to 15. The while loop condition checks if z is less than or equal
to 20. Inside the loop, z is incremented by 2. The loop continues until z becomes greater than
20. After the loop, the value of z, which is 21, is printed followed by a new line. Therefore, the
output from the given fragment is 21.
Rate this question:
2.
Which of the following program fragments is an infinite loop?/* fragment P */z = 10 ;while (z <=
20) z = z + 1 ;/* fragment Q */z = 30 ;while (z <= 20) z = z - 1 ;/* fragment R */z = 10 ;while (z <=
20) ;z = z + 1 ;
A.
Only P
B.
Only Q
C.
Only R
,D.
P and Q
E.
P and R
Correct Answer
C. Only R
Explanation
The correct answer is only R. Fragment R is an infinite loop because the condition in the while
loop is always true (z
Rate this question:
3.
Which of the following statements about value parameters is true?
A.
The argument is never modified by execution of the called function
B.
The parameter is never modified by execution of the called function
, C.
The argument must be a variable
D.
The argument can not have a Boolean value
E.
Both a and b
Correct Answer
A. The argument is never modified by execution of the called function
Explanation
The correct answer is that the argument is never modified by the execution of the called
function. This means that when a function is called with a value parameter, the value of the
argument remains unchanged throughout the execution of the function. The function can
perform operations on the parameter, but it cannot modify the original argument that was
passed to it.
Rate this question:
4.
Which of the following statements about const value parameters is true?
A.
The argument is never modified by execution of the called function