What is a variable in C++?
A variable is a named object that stores a value during program execution. Its type determines representable values, storage requirements, and valid operations.
Study 2 Variables and Data Types with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a variable in C++?
A variable is a named object that stores a value during program execution. Its type determines representable values, storage requirements, and valid operations.
What does a variable declaration specify?
A declaration introduces a variable’s name and type. An initializer gives the variable its first value, as in int count = 20;.
What rules apply to C++ identifiers?
An identifier may contain letters, digits, and underscores, but it cannot begin with a digit or be a reserved keyword. C++ identifiers are case-sensitive.
How do initialization and assignment differ?
Initialization creates an object and supplies its first value. Assignment replaces the value of an existing object, such as width = 25; after int width{10};.
Why should local variables be initialized?
An uninitialized local variable may contain an indeterminate value. Reading it can produce incorrect results or undefined behavior.
What values does bool represent?
A bool represents a logical condition and stores true or false. In conditions, zero converts to false and a nonzero number converts to true.
How do signed and unsigned integers differ?
Signed integer types represent negative and positive values. Unsigned types represent only nonnegative values and can wrap when subtraction would produce a negative result.
Why can floating-point equality be unreliable?
Floating-point types represent real-number approximations, so values such as 0.1 may not be exact. Exact equality comparisons can therefore behave unexpectedly.
When should C++ use const or constexpr?
Use const for an object that must not be modified after initialization. Use constexpr when a value is required or intended to be computable at compile time.
What does x += y mean?
The compound assignment x += y is equivalent to x = x + y. Related forms include -=, *=, /=, and %=; they combine an operation with assignment.
What is the result of integer division 7 / 2?
When both operands of / are integers, C++ performs integer division and discards the fractional part. Thus, 7 / 2 produces 3, while 7.0 / 2 produces 3.5.
How does short-circuit evaluation work?
For A && B, B is evaluated only when A is true. For A || B, B is evaluated only when A is false; this can guard operations such as division.
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
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.
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.
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.
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.