POINTERS QUIZZES

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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.

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.

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.

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.

Pointers may be assigned to which of the following?

Both (b) and (c).

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

By value with pointer arguments.

A string array is commonly used for:

Command-line arguments.

strtok does not:

Completely tokenize the string the first time it is called.

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

Dereferencing a variable that is not a pointer.

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

Is a call to the function pointed to by max.

A string array:

Is actually an array of pointers.

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; } What method does the function use to refer to array elements?

Pointer/offset notation.

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

Pointer/offset notation.

Pointers cannot be used to:

Reference values directly.

sizeof:

Returns the total number of bytes in a variable.

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.

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

Two pointers to ints.

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

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

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.

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


Ensembles d'études connexes

MGMT 310 Organizational Behavior

View Set

Nursing Fundamentals Chapter 10 Communication

View Set

What is the formula for the area of a rectangle?

View Set