C++ Chapter 12, CSC102 Chapter 12 Quiz, CSC, BTE320 Chapter 10, CSC161 Exam 1, C++ chp10, CSC102 Ch 10 Quiz

Ace your homework & exams now with Quizwiz!

In C++, ____ is called the address of operator.

&

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.

What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl;

12, 81

What is the output of the following statements? int x = 33; int *q; q = &x; cout << *q << endl;

33

What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl;

43, 43

What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46;

46

Which of the following operations is allowed on 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.

A class and its members can be described graphically using a notation known as the ____ notation. a. OON b. OOD c. UML d. OOP

C. UML

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.

In C++, pointer variables are declared using the reserved word pointer.

False

In C++, the dot operator has a lower precedence than the dereferencing operator.

False

In C++, the member access operator arrow is >>.

False

In the statement int* p, q; p and q are pointer variables.

False

Variables that are created during program execution are called static variables.

False

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.

If a member of a class is ____, you cannot access it outside the class.

Private

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

A pointer variable is a variable whose content is a memory address

True

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

If p is a pointer variable, the statement p = p + 1; is valid in C++.

True

The dereferencing operator is also known as the indirection operator and refers to the object to which its operand points.

True

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)

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. a. + b. - c. # d. $

a. +

In C++, the ____ is called the member access operator. a. . b. , c. :: d. #

a. .

A class is an example of a structured data type. a. True b. False

a. True

If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class. a. True b. False

a. True

In C++ terminology, a class object is the same as a class instance. a. True b. False

a. True

In C++, class is a reserved word and it defines only a data type. a. True b. False

a. True

Which of the following class definitions is correct in C++? a. class studentType { public: void setData(string, double, int); private: string name; }; b. class studentType { public: void setData(string, double, int); void print() const; private: string name; double gpa; } c. class studentType { public void setData(string, double, int); private string name; }; d. studentType class { public: void setData(string, double, int); private: string name; };

a. class studentType { public: void setData(string, double, int); private: string name; };

The ____ operator can be used to return the address of a private data member of a class.

address of

As parameters to a function, class objects can be passed by reference only. a. True b. False

b. False

Given the declaration class myClass { public: void print(); //Output the value of x; MyClass(); private: int x; }; myClass myObject; The following statement is legal. myObject.x = 10; a. True b. False

b. False

If an object is created in a user program, then the object can access both the public and private members of the class. a. True b. False

b. False

If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables. a. True b. False

b. False

The public members of a class must be declared before the private members. a. True b. False

b. False

You can use arithmetic operators to perform arithmetic operations on class objects. a. True b. False

b. False

A class object can be ____. That is, it is created each time the control reaches its declaration, and destroyed when the control exits the surrounding block. a. static b. automatic c. local d. public

b. automatic

Consider the accompanying class definition, and the object declaration: rectangleType bigRect(14,10); Which of the following statements is correct? a. bigRect.setLengthWidth(); b. bigRect.setLengthWidth(3.0, 2.0); c. bigRect.length = 2.0; d. bigRect.length = bigRect.width;

b. bigRect.setLengthWidth(3.0, 2.0);

Which of the following class definitions is correct in C++?

b. class studentType { public: void setData(string, double, int); private: string name; };

Consider the UML class diagram shown in the accompanying figure. Which of the following is the name of the class? a. clock b. clockType c. Type d. +clockType

b. clockType

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool 15. The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object. a. static b. const c. automatic d. private

b. const

The components of a class are called the ____ of the class. a. elements b. members c. objects d. properties

b. members

A ____ sign in front of a member name on a UML diagram indicates that this member is a protected member. a. + b. - c. # d. $

c. #

Consider the accompanying class definition, and the declaration: rectangleType bigRect; Which of the following statements is correct? a. rectangleType.print(); b. rectangleType::print(); c. bigRect.print(); d. bigRect::print();

c. bigRect.print();

If a member of a class is ____, you cannot access it outside the class. a. public b. automatic c. private d. static

c. private

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; 20. Consider the accompanying class definition. Which of the following variable declarations is correct? a. rectangle rectangleType; b. class rectangleType rectangle; c. rectangleType rectangle; d. rectangle rectangleType.area;

c. rectangleType rectangle;

clockType -hr: int -min: int -sec: int +setTime(int, int, int): void +getTime(int&, int&, int&) const: void +printTime() const: void +incrementSeconds(): int +incrementMinutes(): int +incrementHours(): int +equalTime(const clockType&) const: bool The word ____ at the end of the member functions in the classclockType specifies that these functions cannot modify the member variables of a clockType object.

const

The ____ constructor is executed when an object is declared and initialized by using the value of another object.

copy

Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? a. none b. zero c. two d. three

d. three

In a ____ copy, two or more pointers have their own data.

deep

An array created during the execution of a program is called a(n) ____ array.

dynamic

Given the statement double *p;, the statement p++; will increment the value of p by ____ byte(s).

eight

Given the declaration int *a;, the statement a = new int[50]; dynamically allocates an array of 50 components of the type ____.

int

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 ____.

member-wise initialization

The components of a class are called the ____ of the class.

members

Which of the following can be used to initialize a pointer variable?

nullptr

The code int *p; declares p to be a(n) ____ variable.

pointer

class rectangleType { public: void setLengthWidth(double x, double y); //Postcondition: length = x; width = y; void print() const; //Output length and width; double area(); //Calculate and return the area of the rectangle; double perimeter(); //Calculate and return the parameter; rectangleType(); //Postcondition: length = 0; width = 0; rectangleType(double x, double y); //Postcondition: length = x; width = y; private: double length; double width; }; Consider the accompanying class definition. Which of the following class variable declarations is correct?

rectangleType rectangle;

Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType?

rulerType(const rulerType& myRuler)

In a ____ copy, two or more pointers of the same type point to the same memory.

shallow

In C++, virtual functions are declared using the reserved word ____.

virtual

reference

void pointerParameters(int* &p, double *q) { . . . } In the function pointerParameters, the parameter p is a(n) ____________________ parameter.


Related study sets

PrepU: Lower Respiratory Disorder

View Set