Chapter 8 Questions (Pointers)

Ace your homework & exams now with Quizwiz!

Is a call to the function pointed to by max.

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

A nonconstant pointer to nonconstant 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. A constant pointer to constant data b. A nonconstant pointer to constant data c. A nonconstant pointer to nonconstant data d. A constant pointer to nonconstant data

A nonconstant pointer to constant data.

A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is: a. A constant pointer to constant data b. A nonconstant pointer to constant data c. A nonconstant pointer to nonconstant data d. A constant pointer to nonconstant data

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

A pointer can not be assigned to:

Command-line arguments.

A string array is commonly used for:

Is actually an array of pointers.

A string array:

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

After the ith iteration of the selection sort: a. The smallest i items of the array will be sorted into increasing order int the first i elements of the array b. The smallest i items of the array will be sorted into decreasing order in the first i elements of the array c. The largest i items of the array will be sorted into decreasing order in the last i elements of the array d. None of the above

Dereferencing a variable that is not a pointer

All of the following could cause a fatal execution-time error except: a. Dereferencing a variable that is not a pointer b Dereferencing a pointer that has not been assigned to point to a specific address c. Dereferencing a null pointer d. Dereferencing a pointer that has not been initialized properly

Suffer from indefinite postponement.

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

A constant pointer to nonconstant data.

An array name is: a. A constant pointer to constant data b. A nonconstant pointer to constant data c. A nonconstant pointer to nonconstant data d. A constant pointer to nonconstant data

Strncmp( string1, string2, 5 );

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

&t[ 3 ]

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

They point to elements of the same array.

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

Pointer/offset notation.

Consider the following function: void reverse( char * string1, const char * string2 ) { int stringsize = sizeof( string1 )/sizeof( char ); *( string1 + stringsize -1 ) = '\0'; string1 = string1 + stringsize - 2; for ( ; *string2 != '\0'; string1--, string2++ ) *string1 = *string2; }

2012

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?

Reference values directly

Pointers cannot be used to: a. Pass an argument by reference b. Manipulate dynamic data structures c. Reference values directly d. Contain memory addresses

Both (b) and (c)

Pointers may be assigned to which of the following? a. An address b. Any integer values c. NULL d. Both (b) and (c)

lvalues

The & operator can be applied to: a. string literals b. constants c. rvalues d. lvalues

*Ptr

Three of the following expressions have the same value. Which of the following expressions has a value different from the others? a. &*Ptr b. *&Ptr c. *Ptr d. Ptr

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. A constant pointer to constant data b. A nonconstant pointer to constant data c. A nonconstant pointer to nonconstant data d. A constant pointer to nonconstant data

One pointer to an int and one int variable

What does the following declaration declare? int *countPtr, count; a. The declaration is invalid b. Two int variables c. One pointer to an int and one int variable d. Two pointers to ints

A constant pointer to constant data.

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. A constant pointer to constant data b. A nonconstant pointer to constant data c. A nonconstant pointer to nonconstant data d. A constant pointer to nonconstant data

int *a

When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to: a. int &a b. No conversion is necessary. c. int a d. int *a

++

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

strcpy( string1, string2 );

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"?

sizeof r / sizeof ( int ).

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

By value with pointer arguments

Which of the following is not a valid way to pass arguments to a function in C++? a. By reference with reference arguments b. By value c. By value with pointer arguments d. By reference with pointer arguments

They can not be assigned to other function pointers.

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

String literals are written inside of single quotes.

Which of the following is not true?

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

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

Returns the total number of bytes in a variable.

sizeof:

Completely tokenize the string the first time it is called.

strtok does not:


Related study sets

OB EXAM 3 (CH 27, 28, 29, 30, 32, 33, 37)

View Set

Chapter 1: Humans and the Microbial World.

View Set

LSAT logical reasoning Powerscore

View Set

Organizational Culture, Structure, and Design

View Set

Intro to public speaking- final exam

View Set