Exam 2 Practice(other sources)
1. A virtual function...
a) dynamically dispatches at runtime if the receiver is specified by a pointer or a reference
b) can be overridden
c) is used to implement encapsulation
d) a and b
e) a and c
2. "Heap memory" is another name for...
a) static memory
b) temporary memory
c) the free store
d) the stack
e) none of the above
3. The stack...
a) is used to pass functions to arguments
b) is used to allocate local variable
c) is allocated by new and deallocated by delete
d) all of the above
e) none of the above
4. The Shape class...
a) keeps track of the number of classes derived from Shape
b) keeps track of line length
c) keeps track of line color, width, and style (solid, dashed, etc.)
d) keeps track of the number of Shape objects
e) none of the above
5. Given int *f(0); what is the type of f?
a) pointer to function returning int
b) function of one int returning an int
c) function of one int returning a pointer to int
d) pointer to function of one int returning an int
e) none of the above
6. C++ allows users to define...
a) classes
b) functions
c) enumerations
d) some operators like >> or <<
e) all of the above
7. A destructor for the Shape class
a) is named ~Shape
b) is named Shape::Destructor
c) should close all files
d) is not allowed
e) none of the above
8. The Shape constructor is protected...
a) so that it can be used by derived classes
b) so that one can make Shape object directly
c) so that it cannot be used by derived classes
d) to make it visible only inside the class
e) to make it visible only outside the class
9. What does the following mean? double *x(double);
a) a double number multiplied by x
b) b x is a function of one double returning a pointer to a double
c) dereference double to get x
d) x is a pointer to double
e) none of the above
10. "new allocates memory from _ and returns __ the allocated memory. "
a) a/the pointer (to)
b) a/the stack
c) a/the free store
d) a/the size(of)
e) a/the vector (of)
CA
11. Which one of the following is true regarding the computer's memory?
a) The memory layout consists of five regions: code, static data, references, free store, and stack
b) Local variables live forever one the stack
c) The source codes are in the code section
d) Global variables are in free store
e) None of the above
12. Which one of the following is true regarding pointers?
a) Pointer values are memory addresses
b) A pointer knows how many elements it points to
c) A pointer (other than *void) does not know the type of the object that it is pointing to.
d) There are implicit conversations between a pointer and to one value type to a pointer to another value type
e) One cannot print out the pointer value
13. Which one of the following is true regarding memory leaks?
a) Lack of de-allocation is usually not a serious problem in real world programs, whereas memory leaks are
b) A program that runs to completion with predictable memory usage may leak without causing problems
c) A program that need to run forever can usually afford memory leaks
d) With the following line of code: int *p = 0; the following line of code will cause a memory leak: delete p;
e) none of the above
14. Which one of the following is true regarding references?
a) A reference must not be initialized
b) The value of a reference can be changed by an assignment operation
c) A reference can be thought of as an alternate name for an object
d) A reference need to be explicitly dereferenced like a pointer
e) None of the above
15. Which of the following is true regarding void*?
a) void means "a pointer to an object of type void"
b) To use a void we do no need to tell the compiler what it points to
c) Any pointer to an object can be assigned to void
d) The following is illegal: typedef void Address;
e) None of the above
16. vector is the preferred class for a list of data items since...
a) it requires minimal excess memory
b) the items can be accessed efficiently
c) it is expandable
d) all of the above
e) none of the above
17. A pointer object...
a) occupies memory
b) has a value which is the address of another object, or nullptr
c) may be changed unless it is const
d) all of the above
e) none of the above
18. A reference...
a) occupies memory
b) has a value which is the address of another object, or nullptr
c) may be changed unless it is const
d) all of the above
e) none of the above
19. An abstract class...
a) is used as a base class
b) is used as a derived class
c) has objects with common features
d) all of the above
e) none of the above
20. Which one of the following is true regarding string s and vectorvc?
a) s+vc is a valid operation that concatenates s and vc
b) s+s is a valid operation that concatenates s to itself ***
c) vc+vc is a valid operation that concatenates vc to itself
d) vc.c_str() is a valid operation
e) All of the above are not true
Last updated
Was this helpful?