Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 4 fuera de 42 páginas
Examen

Absolute C 6th Edition Savitch TEST Chapter 2 - Test Questions with verified accurate solutions.

Document preview thumbnail
Vista previa 4 fuera de 42 páginas

Absolute C 6th Edition Savitch TEST Chapter 2 - Test Questions with verified accurate solutions.

Vista previa del contenido

Absolute C+ 6th Edition




Absolute C++ 6th Edition Savitch
TEST Chapter 2 - Test Questions
with verified accurate solutions
These test questions are true-false, fill in the blank, multiple choice, and free form
questions that may require code. The multiple choice questions may have more than one
correct answer. You are required to mark and comment on correct answers.. Mark all of
the correct answers for full credit. The true false questions require an explanation in
addition to the true/false response, and, if false, also require a correction.


True False:

1. The if, while and for statements control only one statement.

Answer: True

Explanation: The one statement may be a block (statements that are enclosed with
curly braces { }) or a simple statement.


2. Given the declaration

int x = 0;

The following expression causes a divide by zero error:

(x !=0) || (2/x < 1);

Answer: False.

Explanation: The || operator uses short-circuit evaluation. The first member of this

expression is true; the truth value of the complete expression can be determined

from this; consequently, the second expression is not evaluated. There is no divide-
by-zero error.
Absolute C+ 6th Edition Savitch TEST Chapter 2 - Test Questions with verified accurate solutions

,3. Suppose we have these declarations,

int x = -1, y = 0, z = 1;




This Boolean expression is correct and it does what the programmer intends.

(x < y < z

Answer: False




Absolute C+ 6th Edition Savitch TEST Chapter 2 - Test Questions with verified accurate solutions

,Test Bank for Savitch Absolute C++ 6e


Page 2


Explanation: Unfortunately, the expression compiles without error and runs. The <

operator associates (groups) left to right, so the expression evaluates as



(x < y) < z

The left hand expression evaluates to true, which, if compared to a numeric type,

converts to 1. When compared to 1, this is false. What the programmer intends,

expressed as mathematacs might is -1 < 0< 1, a result that is clearly true.

4. You want to determine whether time has run out. The following code correctly

implements this.


!time > limit

Answer: False.

Explanation: The expression always evaluates to false. This cannot be what the

programmer intended. The compiler doesn’t catch the problem because the code is

legal, correct C++. Corrected code is !(time > limit)



Code execution proceeds as follows: The operator ! takes a bool argument. It

returns the opposite bool value. The value of time is converted to a bool. The

value of time is certainly nonzero, hence !time is !true, i.e., false. The >

compares this result with a numeric value, limit, (an int or perhaps some kind

of floating point). The value on the left (false) is converted to a 0 value of that

type. The value of limit is unlikely to be a negative number and we are

, concerned about time running out, so it is unlikely that time is zero. Consequently,

the inequality becomes 0>limit, where limit is nonzero. This is false.



5. The value of count is 0; limit is 10. Evaluate:

(count == 0)&&(limit < 20)

Answer: true


6. The value of count is 0; limit is 10. Evaluate:

count == 0 && limit < 20

Answer: true




Absolute C+ 6th Edition Savitch TEST Chapter 2 - Test Questions with verified accurate solutions

Información del documento

Subido en
30 de junio de 2026
Número de páginas
42
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$21.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Examdoctor1
3.7
(6)
Vendido
33
Seguidores
12
Artículos
2986
Última venta
2 meses hace


Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes