Free Practice Quiz Question List

10 Building C++ Programs Online Quiz Questions

Use this free practice quiz with 20 questions to review 10 Building C++ Programs, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

A built-in C++ array is declared as int values[5];. Which range contains all and only its valid indices?

  1. A

    0 through 5

  2. B

    0 through 4

  3. C

    1 through 5

  4. D

    1 through 4

02
True or false
1 point

In the Counter class, does the declaration int getValue() const indicate that the member function does not modify the Counter object?

  1. A

    True

  2. B

    False

03
Written response
1 point

What C++ term describes the result of reading values[5] when values was declared as int values[5];?

04
Fill in the blank
1 point

Complete the design principle: When passing a built-in array to a function, pass the array's separately so the function knows how many elements it may process.

05
Choose one
1 point

In the function call doubleValue(&value), followed by the statement *number *= 2, what are the roles of & and *?

  1. A

    & dereferences a pointer and * obtains an address

  2. B

    Both & and * obtain addresses

  3. C

    & obtains an address and * dereferences a pointer

  4. D

    Both & and * dereference pointers

06
True or false
1 point

If NDEBUG is defined before including <cassert>, are ordinary assertions disabled?

  1. A

    True

  2. B

    False

07
Choose all
1 point

Which two practices help a function process an array safely when the number of elements matters? Select all correct choices.

  1. A

    Pass the array size as a separate parameter

  2. B

    Assume the function can infer the array length from const int values[]

  3. C

    Use a size-aware type such as std::array or std::vector when appropriate

  4. D

    Omit bounds information because the loop condition will always be safe

08
Written response
1 point

What object-oriented programming concept groups data with its operations while controlling access to the data?

09
Fill in the blank
1 point

In the Counter class, the data member value belongs in the section to prevent unrelated code from changing it directly.

10
Choose one
1 point

In the integrated bestStudent example, what does the return type const Student* communicate about the result?

  1. A

    A copy of the highest-scoring Student, which can always be modified

  2. B

    A pointer to the highest-scoring array element, with modification through that pointer prevented

  3. C

    The index of the highest-scoring student, with no connection to the array

  4. D

    A pointer to a newly allocated student that must always be deleted by the caller

11
Choose all
1 point

Which tests does the Materials identify as useful for bestStudent? Select all correct choices.

  1. A

    A one-student array

  2. B

    Several students with tied scores

  3. C

    A case in which the first student has the highest score

  4. D

    A case in which the last student has the highest score

12
Open ended
1 point

You are designing a small C++ program that reads student scores, determines the best student, and verifies the result. Explain how you would separate input and output, processing, data representation, and testing, and give one benefit of this organization.

13
Choose one
1 point

A C++ program declares a function and calls it, but the corresponding definition is not included in the linked program. Which error category should you expect?

  1. A

    A runtime error caused by invalid user input

  2. B

    A linker error caused by a missing matching function definition

  3. C

    A logic error caused by a wrong calculation

  4. D

    Undefined behavior caused by reading an array element

14
Choose one
1 point

In the practical structure of a beginner C++ program, which component coordinates input, processing, and output?

  1. A

    A class definition stores related data and member functions.

  2. B

    The main function coordinates input, processing, and output.

  3. C

    A header file automatically tests every function.

  4. D

    An array declaration determines the program's user interface.

15
Choose one
1 point

When is a range-based for loop generally the clearest choice for processing an array?

  1. A

    It is required whenever an array has more than four elements.

  2. B

    It is often clearer when the program needs each element but not its index.

  3. C

    It automatically checks every possible pointer dereference.

  4. D

    It allows an array to contain values of different types.

16
Choose one
1 point

A function has the parameter int largest(const int values[], int size). Why is the separate size parameter needed for this array parameter form?

  1. A

    The function can infer the size from the first element.

  2. B

    The function receives the size automatically from the compiler.

  3. C

    The caller should pass the size separately or use a size-aware container.

  4. D

    The function must use pointer arithmetic to discover the size.

17
Choose one
1 point

A function receives an int* number and may be called with nullptr. What should it do before evaluating *number?

  1. A

    Check whether the pointer is nullptr before using *number.

  2. B

    Always allocate a second integer inside the function.

  3. C

    Convert the pointer to an array before dereferencing it.

  4. D

    Use delete on the pointer before modifying the object.

18
True or false
1 point

True or false: Defining NDEBUG before including <cassert> disables ordinary assertions.

  1. A

    True

  2. B

    False

19
Written response
1 point

A range-based loop computes the total of int values[5] = {8, 3, 9, 4, 6};. What value should the total be?

20
Written response
1 point

In the bestStudent example, which C++ operator accesses a member through the pointer winner?