Which statement correctly distinguishes initialization from assignment in C++?
2 Variables and Data Types Online Quiz Questions
Use this free practice quiz with 20 questions to review 2 Variables and Data Types, test your knowledge, and prepare for your next test or exam.
What value and type result from this declaration? int result{7 / 2};
- A
3 - B
3.0 - C
3with typeint - D
3.5with typedouble
Which statement calculates a fractional per-person amount when int total{7}; and int people{2}; are already declared?
- A
double per_person{static_cast<double>(total) / people}; - B
double per_person{total / people}; - C
int per_person{static_cast<double>(total) / people}; - D
double per_person{static_cast<int>(total / people)};
Which of the following can be valid C++ identifiers? Select all correct choices.
- A
item_count - B
2nd_item - C
score2 - D
Score - E
class
Which statements correctly describe short-circuit evaluation in C++? Select all correct choices.
- A
The right side of
A && Bis evaluated only ifAis true. - B
The right side of
A || Bis evaluated only ifAis false. - C
Both operands of
&&and||are always evaluated. - D
Short-circuiting can guard a division by checking that its denominator is nonzero first.
- E
Short-circuiting changes an integer into a floating-point value.
True or false: After const int days_in_week{7}; has been initialized, days_in_week = 8; is an error.
- A
True
- B
False
True or false: Subtracting a larger value from a smaller value in unsigned arithmetic produces an ordinary negative result.
- A
True
- B
False
What C++ built-in type should be used for a variable that stores either true or false?
Which C++ operator produces the remainder of integer division?
Complete the description of this declaration: price{19.99}; declares a variable using .
Complete the equivalent form: x += y is equivalent to .
Explain why 7 / 2 produces 3 in an integer expression and describe how to write the calculation so that it produces 3.5. Include why the timing of the conversion matters.
What value does int result{2 + 3 * 4}; initialize result with, and why?
- A
20because addition is evaluated first - B
14because multiplication has higher precedence - C
24because the operands are evaluated from right to left - D
9because only the first two operands are combined
In C++, converting true to an integer produces 1, while converting false produces 0.
- A
True
- B
False
What value is stored in int whole{7 / 2};?
- A
3 - B
3.5 - C
2 - D
A compilation error
Why does if (denominator != 0 && numerator / denominator > 2) avoid evaluating the division when denominator is zero?
- A
The division is always evaluated before the comparison
- B
The expression converts the denominator to a Boolean value
- C
The division is evaluated only when
denominator != 0is true - D
The expression is invalid because
&&cannot combine comparisons
Which statement would cause a compilation error after these declarations: const int maximum_attempts{3}; int attempts{0};?
- A
maximum_attempts; - B
attempts += 1; - C
maximum_attempts = 4; - D
attempts = 1;
What value is stored in double per_person{static_cast<double>(total) / people}; when int total{7}; and int people{2};?
- A
3 - B
3.5 - C
2 - D
7.0
What C++ cast syntax names the preferred general-purpose form for an explicit type conversion?
In the complete example, what numeric value does total have after the ten-percent discount is applied?
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.