What this quiz covers
This quiz focuses on Arithmetic Operators And Precedence, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
Which vector is returned by the following R expression?
c(1, 2, 3) + 2 * c(3, 2, 1) ^ 2
c(19, 10, 5)c(37, 18, 7)c(49, 36, 25)c(7, 6, 5)R Programming Quiz
Practice Arithmetic Operators And Precedence in R Programming with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
This quiz focuses on Arithmetic Operators And Precedence, giving you a quick way to practice the rules, question types, and explanations that matter most for R Programming.
Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.
Which vector is returned by the following R expression?
c(1, 2, 3) + 2 * c(3, 2, 1) ^ 2
c(19, 10, 5) (correct answer)c(37, 18, 7)c(49, 36, 25)c(7, 6, 5)c(1, 2, 3) + 2 * c(3, 2, 1) ^ 2 step by step:
Step 1 — Exponentiation: c(3, 2, 1) ^ 2 gives c(9, 4, 1)
Step 2 — Multiplication: 2 * c(9, 4, 1) gives c(18, 8, 2)
Step 3 — Addition: c(1, 2, 3) + c(18, 8, 2) gives c(19, 10, 5)
That confirms A is correct.
Each wrong answer reflects a specific order-of-operations mistake. B — c(37, 18, 7) — results from squaring after multiplying: (2 * c(3, 2, 1)) ^ 2 then adding, which inflates each value. C — c(49, 36, 25) — comes from adding the vectors before applying any other operation, then squaring: (c(1,2,3) + 2 * c(3,2,1)) ^ 2, a double ordering error. D — c(7, 6, 5) — treats the entire right side as simple multiplication without exponentiation: c(1,2,3) + 2 * c(3,2,1), skipping the ^2 entirely.
A useful habit: whenever you see ^ in an R expression, handle it first. R respects PEMDAS/BODMAS, and the exponentiation operator ^ sits at the top of that hierarchy. Writing out each step explicitly — as shown above — is the safest way to avoid precedence traps on the exam.What value is assigned to result?
result <- 29 %/% 4 + 29 %% 4 * 3
910 (correct answer)1224%/%, %%, and + and * in R, you're being tested on operator precedence. R evaluates integer division (%/%) and modulo (%%) before addition (+), and multiplication (*) also takes priority over addition — just like standard arithmetic.
Break the expression 29 %/% 4 + 29 %% 4 * 3 into steps:
29 %/% 4 = 7 (integer division: how many times does 4 fit into 29?)29 %% 4 = 1 (remainder: 29 - 7×4 = 1)1 * 3 = 3 (multiplication before addition)7 + 3 = 10 ✓10 is correct.
As for the wrong answers: A) 9 likely comes from forgetting the * 3 step entirely and computing just 7 + 1 + 1 or a similar off-by-one error. C) 12 results from incorrectly adding before multiplying — computing (7 + 1) * 3 / 2 or treating the whole right side as (29 %% 4 + something) * 3. D) 24 suggests someone computed 29 %% 4 * 3 correctly as 3 but then multiplied instead of added: 7 * 3 + something, confusing the operators.
A reliable strategy: whenever you see a complex one-liner, rewrite it with explicit parentheses based on precedence before calculating. In R, %/% and %% share the same precedence level and are evaluated left to right, while * beats +. Annotating operator order before computing will save you on tricky exam questions like this one.What value does R return for this expression?
-3^2 + (-3)^2 * 2
279 (correct answer)-270-3^2 + (-3)^2 * 2. In R, the exponentiation operator ^ has higher precedence than the unary minus, so -3^2 is evaluated as -($3^2$) = -9, not (-3)^2 = 9. The parentheses in (-3)^2, however, force the negation to happen first, giving you 9. Then multiplication runs before addition, so 9 * 2 = 18. Finally: -9 + 18 = 9, confirming B is correct.
Here's why each wrong answer fails. A) 27 likely comes from treating both -3^2 and (-3)^2 as positive 9, then computing 9 + 9 * 2 = 27 — a double error that ignores precedence in the first term. C) -27 might come from applying the negative sign to the entire expression or mishandling multiplication order, producing a fully negative result. D) 0 could arise from incorrectly simplifying -3^2 as 9 and then computing 9 + 9 * 2 - 18 = 0 through some garbled arithmetic — the numbers seem balanced but the logic is flawed.
A reliable tip: whenever you see a negative number raised to a power in R, always ask whether parentheses are present. Without them, ^ binds tighter than -, so -x^n means -($x^n$). When in doubt, run it in the console — R's behavior here differs from what many calculators assume.What value is returned by the following R expression?
8 + 18 / 3 * 2 - 5
15 (correct answer)611178 + 18 / 3 * 2 - 5 step by step. First, handle the division and multiplication from left to right:
18/3=6,then6×2=12
Now substitute back:
8+12−5=15
That confirms A) 15 is correct.
The wrong answers each represent a specific trap. D) 17 likely comes from doing 8 + 18 = 26, then 26 / 3 * 2 - 5, treating the expression purely left-to-right without respecting precedence. C) 11 probably results from computing 18 / (3 * 2) = 3, then 8 + 3 - 5 = 6... actually that gives 6, so C may stem from mishandling the subtraction step after partial correct work. B) 6 could come from grouping 18 / (3 * 2) = 3, then 8 + 3 - 5 = 6 — a classic mistake of applying multiplication before the adjacent division instead of strictly left-to-right.
A useful tip: in R, when * and / appear together, always evaluate them left to right — never assume the * takes precedence over / just because multiplication "feels" more important. You can always use parentheses in your own code to make intent explicit and avoid these ambiguities entirely.What does R return for -2^2 + 1?
What does R return for 20 / 4 / 5?
What value is returned by this R expression?
(7 + 5) %% 5 ^ 2 %/% 4
013 (correct answer)12^ (exponentiation) → %% (modulo) and %/% (integer division) → + (addition). Note that %% and %/% share the same precedence level and evaluate left to right.
Let's walk through (7 + 5) %% 5 ^ 2 %/% 4 step by step. The parentheses resolve first: (7 + 5) = 12. Next, ^ has the highest remaining precedence: 5 ^ 2 = 25. Now the expression reads 12 %% 25 %/% 4. Since %% and %/% share precedence and associate left to right, we evaluate 12 %% 25 first: 12 divided by 25 goes 0 times with remainder 12, so 12 %% 25 = 12. Finally, 12 %/% 4 = 3. The correct answer is C) 3.
Choice A) 0 would result if you mistakenly computed 12 %% 4 = 0, skipping the ^ step entirely. Choice B) 1 has no clean derivation from this expression — it likely comes from misapplying precedence in a different incorrect order. Choice D) 12 is a partial answer: it's the result after the parentheses and modulo steps, but forgetting to apply the final %/% operation.
As a study tip, memorize R's precedence table — especially that ^ outranks %% and %/%, which together outrank arithmetic operators like + and -.What does R return when it evaluates this expression?
48 / 6 * 2 / 4
11684 (correct answer)*) and division (/) share equal precedence, which means R evaluates them left to right — no operator "jumps ahead" of another.
Working through 48 / 6 * 2 / 4 step by step:
48÷6=8
8×2=16
16÷4=4
So R returns 4, making D the correct answer.
Now let's trace each wrong answer to its likely misconception. A (1) would result if you incorrectly divided all the numbers in sequence without respecting left-to-right order — for instance, collapsing the denominators and computing 48÷(6×2×4), which gives 1. B (16) comes from stopping too early — completing only the first two operations (48÷6×2=16) and forgetting the final division by 4. C (8) results from performing only the first operation (48÷6=8) and ignoring the rest of the expression entirely.
A useful strategy: whenever you see a mixed chain of * and / in R, mentally insert parentheses left to right — ((48 / 6) * 2) / 4 — to make the evaluation order explicit. This habit prevents the common trap of treating division as having lower priority than multiplication, which it does not in R.What is the result of evaluating the following expression in R?
2 ^ 3 ^ 2 / 8
83264 (correct answer)512^ (exponentiation) and / (division) in R, your first instinct should be to carefully check operator precedence and associativity — two distinct properties that determine evaluation order.
In R, ^ has higher precedence than /, so exponentiation is evaluated first. But critically, ^ is right-associative, meaning 2 ^ 3 ^ 2 is parsed as 2 ^ (3 ^ 2), not (2 ^ 3) ^ 2. Evaluating right-to-left:
32=9
29=512
512/8=64
So the correct answer is C) 64.
Here's why each wrong answer reflects a specific mistake. A) 8 would result from computing 2^3 = 8 and then incorrectly dividing before handling the second exponentiation — essentially mangling both associativity and precedence. B) 32 comes from misapplying left-to-right associativity: (2^3)^2 = 64, then 64/2 = 32 — a double error of wrong associativity and wrong division operand. D) 512 is actually the intermediate result 2^($3^2$) before dividing by 8 — it's the value you'd get if you forgot the /8 entirely, which is an easy slip when the exponentiation result looks "final."
A reliable study tip: in R, remember the phrase "exponentiation climbs right" — consecutive ^ operators are evaluated from right to left. This is one of R's most commonly tested "gotcha" behaviors and differs from how many students expect math to work.After the following code runs, which choice correctly identifies both the value of x and the result of typeof(x)?
x <- 5L ^ 2L / 2L + 1L
x is 13, and its type is "integer"x is 13.5, and its type is "integer"x is 13.5, and its type is "double" (correct answer)x is 26, and its type is "double"L-suffixed integers in R, you need to think about two things: the math itself, and how R handles type promotion during division.
Let's trace through the expression 5L ^ 2L / 2L + 1L using R's standard operator precedence (exponentiation first, then division, then addition):
52=25,25÷2=12.5,12.5+1=13.5
So x holds the value 13.5. But what's the type? Even though every literal in this expression is an integer (L), the / (division) operator in R always returns a double, regardless of its inputs. Once division produces 12.5, the entire result is promoted to "double", making typeof(x) return "double". That confirms C is correct.
A is wrong on both counts — it claims x is 13 (suggesting integer division, which would require %/%) and that the type is "integer". B gets the value right (13.5) but incorrectly assumes R preserves the integer type through division — it doesn't. D suggests x is 26, which would only result from something like 5L * 2L ^ 2L + 2L; it reflects a misreading of operator precedence.
A reliable rule of thumb: in R, / always yields a double. If you want integer division, you must explicitly use %/%. On exam questions mixing integer literals with arithmetic, always check whether division is involved — if it is, expect "double" as the output type.Which vector is produced by this R expression?
3 + 2 * 1:4
c(5, 10, 15, 20)c(5, 7, 9, 11) (correct answer)c(5, 6, 7, 8)c(5, 4):), operator precedence is everything. R evaluates * and : before +, but crucially, : has higher precedence than *. This means 1:4 is evaluated first, then multiplication, then addition.
Breaking it down: 1:4 produces the vector c(1, 2, 3, 4). Next, 2 * c(1, 2, 3, 4) applies vectorized multiplication, giving c(2, 4, 6, 8). Finally, 3 + c(2, 4, 6, 8) adds 3 to each element, producing c(5, 7, 9, 11) — confirming B is correct.
Choice A, c(5, 10, 15, 20), results from treating the expression as (3 + 2) * 1:4, computing 5 * c(1, 2, 3, 4). This misapplies precedence by letting + run before *. Choice C, c(5, 6, 7, 8), comes from reading it as (3 + 2) + 1:4, i.e., 5 + c(1, 2, 3, 4) — ignoring the multiplication entirely. Choice D, c(5, 4), might come from misreading 1:4 as 1 through 4 collapsed into a range arithmetic operation like (3+2*1):(3+2*4) evaluated as endpoints only, which is not how R works here.
A handy tip: in R, remember the mnemonic Colon before Multiplication before Addition. When in doubt about precedence, wrap subexpressions in parentheses and test in the console — it's a quick habit that prevents these traps on the exam.What value results from the following R expression?
(2 + 3) ^ 2 - 2 + 3 ^ 2
0102032 (correct answer)^), then addition and subtraction left to right.
Let's walk through (2 + 3) ^ 2 - 2 + 3 ^ 2 step by step:
(2+3)2−2+32
=52−2+32
=25−2+9
=32
So the correct answer is D) 32.
Here's where the wrong answers come from: A) 0 likely results from treating the entire expression as (2 + 3)^2 - (2 + 3)^2, incorrectly grouping terms symmetrically — a pure misread. B) 10 might come from computing (2 + 3)^2 - 2 + 3 without applying the exponent to the final 3^2, treating it as plain 3 rather than 9. C) 20 is a common trap — it results from incorrectly applying subtraction and addition right-to-left or miscomputing 25 - 2 + 9 as 25 - (2 + 9) = 14... actually, C likely comes from computing 5^2 - 2 + 3^2 but using 3^2 = 3 and getting 25 - 2 - 3 = 20, misreading the final + as -.
Study tip: Always scan for every ^ operator in an expression — each one must be evaluated before any addition or subtraction. A common mistake is only applying exponentiation to the parenthesized group and forgetting standalone terms like 3^2.