CSC102 Chapter 12 Quiz
True.
(T/F?) A pointer variable is a variable whose content is a memory address.
False.
(T/F?) In C++, the dot operator has a lower precedence than the dereferencing operator.
False, it is ->
(T/F?) In C++, the member access operator arrow is >>.
False, only p is the ptr var.
(T/F?) In the statement int* p, q; p and q are pointer variables.
destructor
A class ____ automatically executes whenever a class object goes out of scope.
dynamic
An array created during the execution of a program is called a(n) ____ array.
studentPtr->gpa
Consider the following declaration of a struct: struct studentType { char name[26]; double gpa; int sID; char grade; }; studentType student; studentType *studentPtr; The statement (*studentPtr).gpa = 2.5; is equivalent to ___________________ = 2.5;
member-wise initialization
Consider the following statement: ptrMemberVarType objectThree(objectOne); The values of the member variables of objectOne are being copied into the corresponding member variables of objectThree. This initialization is called the ____.
abstract
Consider the following statements: class shape { public: virtual void draw() = 0; virtual void move(double x, double y) = 0; . . . }; The code above is an example of a(n) ____________________ class definition.
value
Consider the following statements: void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter q is a(n) ____________________ parameter.
int
Given the declaration int *a;, the statement a = new int[50]; dynamically allocates an array of 50 components of the type ____.
8
Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s).
& or ampersand
In C++, ____ is called the address of operator.
virtual
In C++, virtual functions are declared using the reserved word ____.
*
In C++, you declare a pointer variable by using the ____ symbol.
static
In ____ binding, the necessary code to call a specific function is generated by the compiler.
deep
In a ____ copy, two or more pointers have their own data.
shallow
In a ____ copy, two or more pointers of the same type point to the same memory.
dynamic
Run-time binding is also known as ____ binding.
True
T/F? A memory leak is an unused memory space that cannot be allocated.
True.
T/F? Given the declaration int *p; The statement p = new int[50]; dynamically allocates an array of 50 components of type int and p contains the base address of the array.
True.
T/F? If p is a pointer variable, the statement p = p + 1; is valid in C++.
False, they are declared using *
T/F? In C++, pointer variables are declared using the reserved word pointer.
True
T/F? The dereferencing operator is also known as the indirection operator and refers to the object to which its operand points.
False
T/F? Variables that are created during program execution are called static variables.
new
The C++ operator ____ is used to create dynamic variables.
delete
The C++ operator ____ is used to destroy dynamic variables.
copy
The ____ constructor is executed when an object is declared and initialized by using the value of another object.
address of
The ____ operator can be used to return the address of a private data member of a class.
virtual destructor
The ____________________ of a base class automatically makes the destructor of a derived class virtual.
execution or run
The binding of virtual functions occurs at program ____________________ time.
pointer
The code int *p; declares p to be a(n) ____ variable.
value
The copy constructor automatically executes when, as a parameter, an object is passed by ____________________.
int* p;
The statement int *p; is equivalent to int * p;, which is also equivalent to the statement ____________________.
*board[6]
The statement that declares board to be an array of six pointers wherein each pointer is of type int is: int ____________________;
12, 81
What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl;
43, 43
What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl;
33
What is the output of the following statements? int x = 33; int *q; q = &x; cout << *q << endl;
46
What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46;
Increment
Which of the following arithmetic operations is allowed on pointer variables? a. Multiplication b. Division c. Increment d. Modulus
nullptr
Which of the following can be used to initialize a pointer variable? a. '0' b. 1 c. "0" d. nullptr
==
Which of the following operations is allowed on pointer variables? a. % b. / c. == d. exp
rulerType(const rulerType& myRuler)
Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType? a. rulerType() b. copy rulerType(int inches, int centimeters) c. rulerType(const rulerType& myRuler) d. rulerType(int inches, int centimeters)
reference
void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter p is a(n) ____________________ parameter.