Pointers

¡Supera tus tareas y exámenes ahora con Quizwiz!

A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is:

A nonconstant pointer to constant data

A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:

A nonconstant pointer to nonconstant data

A pointer can not be assigned to:

A pointer of a type other than its own type and void without using the cast operator.

A copy constructor:

Is a constructor that initializes a newly declared object to the value of an existing object of the same class.

A string array:

Is actually an array of pointers.

Which of the following is false about the new operator and the object for which it allocates memory?

It automatically destroys the object after main is exited.

An overloaded + operator takes a class object and a double as operands. For it to be commutative (i.e., a + b and b + a both work):

It must be overloaded twice; the operator+ function that takes the object as the left operand must be a member function, and the other operator+ function must be a global function.

When composition (one object having another object as a member) is used:

Member objects are constructed first, in the order they are declared in the host's class.

To use an operator on user-defined class objects, operator overloading

Must always be used, with three exceptions

Which of the following is false? An explicit constructor:

Must take exactly one argument.

If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?

The President.

Which situation would require the operator to be overloaded as a global function?

The left operand is an int

The array subscript operator [], when overloaded, cannot:

Take multiple values inside (e.g., [4 8]).

For a non-constant member function of class Test, the this pointer has type:

Test * const.

To implicitly overload the += operator:

The += operator cannot be overloaded implicitly

Which of the following operators cannot be overloaded?

The . operator.

Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string "ABCDEFGHI", what string does string1( 4 , 2 ) return?

"EF"

Which of the following capabilities do "raw" C++ arrays not provide?

"Raw" arrays do not provide any of the above capabilities

Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of the fourth element?

&t[ 3 ]

Three of the following expressions have the same value. Which of the following expressions has a value different from the others'?

*Ptr

Inside a function definition for a member function of an object with data element x, which of the following is not equivalent to this->x:

*this.x

Which of the following can have a pointer as an operand?

++

Given that k is an integer array starting at location 2000, kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to?

2012

The numbers 3, 2, 5, 7 are enqueued in a queue in that order, then three numbers are dequeued, and finally 3, 7, 9, 4 are enqueued in that order. What is the first number in the queue (the next number to be dequeued)?

7

Which of the following operators can be overloaded as a global function?

==

Which of the following is not true about friend functions and friend classes?

A class can either grant friendship to or take friendship from another class using the friend keyword.

What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation:

A constant pointer to constant data

An array name is:

A constant pointer to nonconstant data

To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:

A constant pointer to nonconstant data.

Which of the following is not an abstract data type?

A for loop.

An error occurs if:

An object data member is not initialized in the member initialization list and does not have a default constructor.

For operators overloaded as non-static member functions:

Binary operators can have one argument, and unary operators cannot have any.

To prevent class objects from being copied:

Both (a) and (b).

Which of the following is not a valid way to pass arguments to a function in C++?

By value with pointer arguments

Which of the following is false?

C++ ensures that you cannot "walk off" either end of an array.

Conversion constructors:

Can convert between user-defined types

The delete operator:

Can delete an entire array of objects declared using new.

static member functions:

Can only access other static member functions and static data members

Which statement about operator overloading is false?

Certain overloaded operators can change the number of arguments they take

If the line: friend class A; appears in class B, and the line: friend class B; appears in class C, then:

Class A can access private variables of class B.

A string array is commonly used for:

Command-line arguments.

There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is being overloaded to postincrement an object of type Date. Select the correct implementation:

Date Date::operator++( int ) { Date temp = *this; Increment(); return temp; }.

Which of the following statements will not produce a syntax error?

Declaring an object to be const.

all of the following could cause a fatal execution-time error except

Dereferencing a variable that is not a pointer.

static data members of a certain class:

Have class scope.

I. Captures a data representation. II. Defines the operations that are allowed on its data. III. Replaces structured programming.

I and II

( *max )( num1, num2, num3 );

Is a call to the function pointed to by max.

Copy constructors must receive its argument by reference because:

Otherwise infinite recursion occurs.

Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

Requiring the explicit overloading of the assignment operator.

sizeof:

Returns the total number of bytes in a variable.

The prototypes of overloaded cast operator functions do not:

Specify a return type

Which of the following is not true?

String literals are written inside of single quotes.

Assuming that string1 = "hello" and string2 = "hello world", which of the following returns 0?

Strncmp( string1, string2, 5 );

An algorithm that could execute for an unknown amount of time because it depends on random numbers may:

Suffer from indefinite postponement.

After the ith iteration of the selection sort:

The smallest i items of the array will be sorted into increasing order in the first i elements of the array

Which of the following is not true of pointers to functions?

They can not be assigned to other function pointers

Comparing pointers and performing pointer arithmetic on them is meaningless unless:

They point to elements of the same array

Which of the following lines would be the prototype for an overloaded cast operator function that converts an object of user-defined type Time into a double?

Time::operator double() const;

The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:

To make the argument list of postincrement include an int.

Instead of including a string data type among C++'s built-in data types, C++: a. Was designed to include mechanisms for creating and implementing string abstract data types through classes

Was designed to include mechanisms for creating and implementing string abstract data types through classes

pointers may be assigned to

both b and c

cin.getline( superstring, 30 ); is equivalent to which of the following?

cin.getline( superstring, 30, '\n' );

Increment::Increment( int c, int i ) : increment ( i ) { count = c; } does not cause any compilation errors. This tells you that:

count must be a non-const variable.

Which of the following is not a type of container (collection) class?

floats

When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

int * a

the & operator can be applied to

lvalues

What does the following declaration declare? int *countPtr, count;

one pointer and one int

the correct function name for overloading the addition (+) operator is

operator+

Suppose you have a programmer-defined data type Data and want to overload the << operator to output your data type to the screen in the form cout << dataToPrint; and allow cascaded function calls. The first line of the function definition would be:

ostream &operator<<( ostream &output, const Data &dataToPrint )

Which of the following is not an operator overloaded by the C++ language?

pow

pointers cannot be used to

reference values directly

Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression !s?

s.operator!().

Which of the following gives the number of elements in the int array r[ ]?

sizeof r / sizeof ( int )

Which of the following correctly copies the contents of string2 into string1? Assume that string2 is equal to "goodbye" and string1 is equal to "good morning"?

strcpy( string1, string2 );.

Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() is declared void, which of the following statements will not produce a syntax error:

t.a().b().d();

y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?

y.operator+=( z ).


Conjuntos de estudio relacionados

The Tempest Act 2 &3 Study Guide

View Set

API Ch 29 Human Development & Inheritance Mastering HW, DSM, Study Area

View Set

Fluid & Electrolytes Content Post Test- HURST

View Set

CH 39 - Fluid, Electrolyte, and Acid-Base Balance

View Set

Physiology of the Normal Menstrual Cycle

View Set

Module 1: clinical communication

View Set

ACCT 302 Chap 3 Cost Volume Profit

View Set