Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

A C++ function performs an action but does not return a value. Which return type should its declaration use?

  1. A

    nullptr_t

  2. B

    void

  3. C

    bool

  4. D

    char

02
Choose one
1 point

What value is assigned to quotient in this declaration?

int quotient = 7 / 2;

  1. A

    3.5

  2. B

    3

  3. C

    4

  4. D

    1

03
Written response
1 point

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

04
Written response
1 point

What integer value does score contain after this statement?

int score = 10; score += 5;

05
Choose one
1 point

What value is assigned to result?

int result = 2 + 3 * 4;

  1. A

    20

  2. B

    24

  3. C

    14

  4. D

    9

06
Choose all
1 point

Which C++ built-in types are floating-point types? Select all correct choices.

  1. A

    float

  2. B

    double

  3. C

    long double

  4. D

    int

  5. E

    bool

07
Choose all
1 point

Which statements about const and constexpr variables are correct? Select all correct choices.

  1. A

    A const variable cannot be modified after initialization.

  2. B

    A const variable may be declared without an initializer and assigned later.

  3. C

    Every constexpr variable is constant.

  4. D

    Every const variable is necessarily a compile-time constant.

  5. E

    A constexpr variable can be reassigned after initialization.

08
True or false
1 point

True or false: In C++, for the expression A && B, the right operand B is evaluated only when A is true.

  1. A

    True

  2. B

    False

09
True or false
1 point

True or false: In C++, the operator = tests whether two values are equal, while == assigns a value.

  1. A

    True

  2. B

    False

10
Fill in the blank
1 point

Complete the statement with one word: A local built-in variable should be before it is read.

11
Fill in the blank
1 point

Complete the statement: The operator = is called the operator.

12
Open ended
1 point

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.

13
Choose one
1 point

Which statement accurately describes an unsigned integer type in portable C++?

  1. A

    It is guaranteed to be exactly 32 bits on every implementation.

  2. B

    It can represent negative values and no positive values.

  3. C

    It represents zero and nonnegative values and may have a larger maximum than the corresponding signed type.

  4. D

    It always uses less storage than the corresponding signed type.

14
Choose one
1 point

What value is printed by this program?

int value = 1;

int main() {

int value = 2;

std::cout << value;

}

  1. A

    1

  2. B

    2

  3. C

    The program cannot declare two variables named value.

  4. D

    The expression is undefined because both variables are visible equally.

15
Choose one
1 point

Consider this C++ code: const int maximum_attempts{3}; maximum_attempts = 4; What is the result?

  1. A

    The assignment is valid because maximum_attempts is an integer.

  2. B

    The assignment is invalid because maximum_attempts is const.

  3. C

    The assignment is valid only if the new value is smaller.

  4. D

    The assignment changes the object only at compile time.

16
Choose one
1 point

What value is assigned to quotient in this statement? int quotient = 7 / 2;

  1. A

    3.5

  2. B

    4

  3. C

    3

  4. D

    1

17
Choose one
1 point

Given int value = 1; int main() { int value = 2; std::cout << value; }, what value is printed?

  1. A

    2

  2. B

    1

  3. C

    Both values are printed.

  4. D

    The program fails because two variables cannot share a name.

18
True or false
1 point

Every constexpr variable is const, but a const variable is not necessarily a compile-time constant.

  1. A

    True

  2. B

    False

19
Written response
1 point

What numeric value does static_cast<double>(7) / 2 produce?

20
Written response
1 point

What C++ cast operator is used in static_cast<char>(code) to make the numeric conversion explicit?