C++ Practice Final Exam Questions

25 Questions | Total Attempts: 1043

SettingsSettingsSettings
Please wait...
C Programming Quizzes & Trivia

Practice final for C++.


Questions and Answers
  • 1. 
    Declare an array to hold 10 integers. 
    • A. 

      Int nums[9];

    • B. 

      Int[9] nums;

    • C. 

      Int nums[10];

    • D. 

      Int[10] nums;

    • E. 

      Int billy = new int[10];

  • 2. 
    Everything you can do in C, you can do in C++.
    • A. 

      True

    • B. 

      False

  • 3. 
    The function "malloc" is used in C to dynamically allocate memory. What is the equivalent of "malloc" in C++?
    • A. 

      Cpp_malloc

    • B. 

      Create_new

    • C. 

      Mem_create

    • D. 

      New

  • 4. 
    Which of the following function prototypes declares a reference to the int "numPlayers"?
    • A. 

      Void startGame(int numPlayers&);

    • B. 

      Void startGame(int& numPlayers);

    • C. 

      Void startGame(int* numPlayers);

    • D. 

      Void startGame(int numPlayers*);

  • 5. 
    In C++ you must end a class declaration with what character?
    • A. 

      A right curly bracket.

    • B. 

      A right brace.

    • C. 

      Double colons.

    • D. 

      A semi-colon.

  • 6. 
    By default, class variables and methods in C++ are __________.
    • A. 

      Protected

    • B. 

      Public

    • C. 

      Private

    • D. 

      Overloaded

  • 7. 
    Bob and Alice are both C++ classes with a private member "secret" of type string. Pick the best option that allows Class Alice to access Class Bob's private member "secret". 
    • A. 

      Have Class Bob "friend" Class Alice.

    • B. 

      Have Class Alice "friend" Class Bob.

    • C. 

      Make "secret" public.

    • D. 

      Create a public member functions for Alice and Bob called getSecret().

  • 8. 
    Class Animal contains a virtual function "speak". Class Cat and Class Dog are derived from Class Animal. (e.g., They both inherit from Class Animal.) Which of the following best describes Class Animal?
    • A. 

      Class Animal is a virtual block class.

    • B. 

      Class Animal is a friend of Class Cat and Class Dog.

    • C. 

      Class Animal is an abstract base class.

    • D. 

      Class Animal is an interface.

  • 9. 
    The following is a code snippet from Class Dog:Dog::Dog(const Dog &D);What best describes this function prototype?
    • A. 

      Class Constructor

    • B. 

      Copy Constructor

    • C. 

      Virtual Constructor

    • D. 

      Overloaded Abstract Virtual Constructor

  • 10. 
    Line 1: Person q("Mickey");Line 2: Person r(p);Line 3: Person p = q;Line 4: p = q;For what lines above is a copy constructor invoked?
    • A. 

      2

    • B. 

      3

    • C. 

      2,3

    • D. 

      2,3,4

  • 11. 
    When is a copy constructor implicitly called?
    • A. 

      Passing an object by value to a function.

    • B. 

      Returning an object by value from a function.

    • C. 

      Both a and b.

    • D. 

      Passing an object by reference to a constructor.

  • 12. 
    Line 1: Person a;Line 2: Person b = a;Is line two an implicit or explicit call to the Person copy constructor?
    • A. 

      Implicit

    • B. 

      Explicit

    • C. 

      Both

    • D. 

      None

  • 13. 
    Int main(){Person a;Person b;Person c;return 0;}Which object's destructor is called first?
    • A. 

      Person a

    • B. 

      Person b

    • C. 

      Person c

    • D. 

      None of the above

  • 14. 
    Destructors are only needed when you have pointers. 
    • A. 

      True

    • B. 

      False

  • 15. 
    You can free a pointer in C++ using a "delete". Which keyword can you use to free an array?
    • A. 

      Free

    • B. 

      Free[]

    • C. 

      Delete

    • D. 

      Delete[]

  • 16. 
    Review *r = newReview();How would you free the memory allocated above?
    • A. 

      Free(r);

    • B. 

      Delete r;

    • C. 

      Delete[] r;

    • D. 

      ~r();

  • 17. 
    Int*r= new int[5];How would you free the memory allocated above?
    • A. 

      Free(r);

    • B. 

      Delete r;

    • C. 

      Delete[] r;

    • D. 

      ~r();

  • 18. 
    Destructors are implicity called on local variables when:
    • A. 

      Exiting a function

    • B. 

      Restarting the operating system

    • C. 

      Exiting a statement (if, while, etc.)

    • D. 

      Both a and c

  • 19. 
    What is wrong with the following statement:Person a = new Person("noah");
    • A. 

      There is nothing wrong.

    • B. 

      You cannot instantiate an object on the same line as it is declared.

    • C. 

      "noah" is a const string that cannot be reassigned inside the Person class.

    • D. 

      Person a is not a pointer.

  • 20. 
    Create a prototype for a const function called "getName" that returns a string.
    • A. 

      Const string getName();

    • B. 

      String getName() const;

    • C. 

      String const getName();

    • D. 

      Const std__str getName();

  • 21. 
    Create a prototype for a function called "search" that takes a const string as a parameter and returns an int.
    • A. 

      Void search(const string);

    • B. 

      Int search(const string) const;

    • C. 

      Int search(const string);

    • D. 

      Int const search(string);

  • 22. 
    Create a prototype for a const function called query that takes a const int as a parameter and returns an immutable Person object. 
    • A. 

      Const Person (const int) const;

    • B. 

      Person const (const int) const;

    • C. 

      Const Person const (const int) const;

    • D. 

      Const Person (const int&) const;

  • 23. 
    Which of the following object-oriented features best describes the "is-a" class relationship?
    • A. 

      Composition

    • B. 

      Inheritance

    • C. 

      Aggregation

    • D. 

      Polymorphism

  • 24. 
    __________ redefines a function (with exactly the same syntax) to do something else. Examples include overloading the copy constructor.
    • A. 

      Abstraction

    • B. 

      Overriding

    • C. 

      Overloading

  • 25. 
    __________ implements the same function name, but different parameters. The simplest example of this is having multiple constructors. 
    • A. 

      Abstraction

    • B. 

      Overriding

    • C. 

      Overloading