AP CSA Unit 1 Day 20: III Expression Evaluation

Unit 1 Advanced (Cycle 2) Day 20 of 28 Advanced

I/II/III: Expression Evaluation

Section 1.3 — Expressions and Assignment

Key Concept

I/II/III format questions about expression evaluation test whether you can apply multiple rules simultaneously. Each statement may involve different combinations of casting, precedence, and type promotion. The strategy is to evaluate each roman numeral statement completely and independently, determining whether it is true or false before looking at the answer choices. If you are confident about two of the three statements, you can often determine the answer without fully evaluating the third.

Consider the following expressions where x = 14 and y = 4.

I. x / y + x % y == x evaluates to false II. (double) x / y == 3.5 evaluates to true III. x / y * y == x evaluates to false

Which of the above statements are correct?

Answer: (D) I, II, and III

Evaluate each with x = 14, y = 4:

I: 14 / 4 + 14 % 4 = 3 + 2 = 5. Is 5 == 14? No, it is false. Wait, but we proved earlier that (a/b)*b + a%b == a. Note: x/y + x%y is NOT the same as (x/y)*y + x%y. Here it is addition without the multiply. 3 + 2 = 5, not 14. Statement says this is false. CORRECT.

II: (double) 14 / 4 = 14.0 / 4 = 3.5. 3.5 == 3.5 is true. Statement says this is true. CORRECT.

III: 14 / 4 * 4 = 3 * 4 = 12. 12 == 14 is false. Statement says this is false. CORRECT.

Why Not the Others?

(A) Statement II is also correct. (double) x / y performs floating-point division giving 3.5.

(B) Statement I is also correct. x / y + x % y = 3 + 2 = 5, which does not equal 14.

(C) Statement III is also correct. Integer division truncates, so (14/4)*4 = 3*4 = 12, not 14.

Common Mistake

The identity (a/b)*b + a%b == a always holds, but (a/b)*b alone does NOT equal a unless a is divisible by b. The truncation from integer division loses the remainder, so multiplying back gives a smaller value.

AP Exam Tip

Read I/II/III statements carefully. They tell you what they evaluate to and ask if that claim is correct. You must both compute the expression AND verify the stated result.

Review this topic: Section 1.3 — Expressions and Assignment • Unit 1 Study Guide

More Practice

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.