A C++ function performs an action but does not return a value. Which return type should its declaration use?
02 Variables, Types, and Operators Online Quiz Questions
Use this free practice quiz with 20 questions to review 02 Variables, Types, and Operators, test your knowledge, and prepare for your next test or exam.
What value is assigned to quotient in this declaration?
int quotient = 7 / 2;
- A
3.5
- B
3
- C
4
- D
1
Which C++ keyword should replace KEYWORD to declare days_per_week as a variable intended for use in constant expressions?
KEYWORD int days_per_week{7};
What integer value does score contain after this statement?
int score = 10; score += 5;
What value is assigned to result?
int result = 2 + 3 * 4;
- A
20
- B
24
- C
14
- D
9
Which C++ built-in types are floating-point types? Select all correct choices.
- A
float
- B
double
- C
long double
- D
int
- E
bool
Which statements about const and constexpr variables are correct? Select all correct choices.
- A
A
constvariable cannot be modified after initialization. - B
A
constvariable may be declared without an initializer and assigned later. - C
Every
constexprvariable is constant. - D
Every
constvariable is necessarily a compile-time constant. - E
A
constexprvariable can be reassigned after initialization.
True or false: In C++, for the expression A && B, the right operand B is evaluated only when A is true.
- A
True
- B
False
True or false: In C++, the operator = tests whether two values are equal, while == assigns a value.
- A
True
- B
False
Complete the statement with one word: A local built-in variable should be before it is read.
Complete the statement: The operator = is called the operator.
Explain why brace initialization is often preferred over assignment-style initialization in C++. Include what happens when a fractional value such as 3.14 is used to initialize an int with each syntax.
Which statement accurately describes an unsigned integer type in portable C++?
- A
It is guaranteed to be exactly 32 bits on every implementation.
- B
It can represent negative values and no positive values.
- C
It represents zero and nonnegative values and may have a larger maximum than the corresponding signed type.
- D
It always uses less storage than the corresponding signed type.
What value is printed by this program?
int value = 1;
int main() {
int value = 2;
std::cout << value;
}
- A
1
- B
2
- C
The program cannot declare two variables named
value. - D
The expression is undefined because both variables are visible equally.
Consider this C++ code: const int maximum_attempts{3}; maximum_attempts = 4; What is the result?
- A
The assignment is valid because
maximum_attemptsis an integer. - B
The assignment is invalid because
maximum_attemptsisconst. - C
The assignment is valid only if the new value is smaller.
- D
The assignment changes the object only at compile time.
What value is assigned to quotient in this statement? int quotient = 7 / 2;
- A
3.5 - B
4 - C
3 - D
1
Given int value = 1; int main() { int value = 2; std::cout << value; }, what value is printed?
- A
2 - B
1 - C
Both values are printed.
- D
The program fails because two variables cannot share a name.
Every constexpr variable is const, but a const variable is not necessarily a compile-time constant.
- A
True
- B
False
What numeric value does static_cast<double>(7) / 2 produce?
What C++ cast operator is used in static_cast<char>(code) to make the numeric conversion explicit?
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.