Free Online Flashcard Deck

2 Variables and Data Types Free Online FlashCards

Study 2 Variables and Data Types with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a variable in C++?

Back

A variable is a named object that stores a value during program execution. Its type determines representable values, storage requirements, and valid operations.

02
Front

What does a variable declaration specify?

Back

A declaration introduces a variable’s name and type. An initializer gives the variable its first value, as in int count = 20;.

03
Front

What rules apply to C++ identifiers?

Back

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.

04
Front

How do initialization and assignment differ?

Back

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};.

05
Front

Why should local variables be initialized?

Back

An uninitialized local variable may contain an indeterminate value. Reading it can produce incorrect results or undefined behavior.

06
Front

What values does bool represent?

Back

A bool represents a logical condition and stores true or false. In conditions, zero converts to false and a nonzero number converts to true.

07
Front

How do signed and unsigned integers differ?

Back

Signed integer types represent negative and positive values. Unsigned types represent only nonnegative values and can wrap when subtraction would produce a negative result.

08
Front

Why can floating-point equality be unreliable?

Back

Floating-point types represent real-number approximations, so values such as 0.1 may not be exact. Exact equality comparisons can therefore behave unexpectedly.

09
Front

When should C++ use const or constexpr?

Back

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.

10
Front

What does x += y mean?

Back

The compound assignment x += y is equivalent to x = x + y. Related forms include -=, *=, /=, and %=; they combine an operation with assignment.

11
Front

What is the result of integer division 7 / 2?

Back

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.

12
Front

How does short-circuit evaluation work?

Back

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.