Pointers

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

C) defines a structure pointer called pcirc.

If Circle is a structure type, the statement Circle *pcirc; A) initializes a Circle pointer. B) defines a structure variable called *pcirc. C) defines a structure pointer called pcirc. D) is illegal in C++. E) None of the above

D) the address of the first byte of storage allocated to it.

If a variable occupies more than one byte of memory, its address is A) the average of the addresses used to store the variable. B) general delivery. C) the address of the last byte of storage allocated to it. D) the address of the first byte of storage allocated to it. E) None of the above

C) *(arr + k).

If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to A) arr + k. B) &arr[k]. C) *(arr + k). D) *arr + k. E) None of the above

B) the system may run out of memory.

If dynamically allocated memory is not freed, A) a run-time error informs your user that the program did not free memory space. B) the system may run out of memory. C) it results in a compiler error. D) the source code will not link correctly. E) None of the above

False

True/False: With pointer variables you can access, but you cannot modify, data in other variables.

C) ampersand ( & )

When the ________ is placed in front of a variable name, it returns the address of that variable. A) conditional operator B) asterisk ( * ) C) ampersand ( & ) D) semicolon ( ; ) E) None of the above

D) the address of the first variable comes before the address of the second variable in the computer's memory.

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether A) the value pointed to by the first is less than the value pointed to by the second. B) the first variable was declared before the second variable. C) the value pointed to by the first is greater than the value pointed to by the second. D) the address of the first variable comes before the address of the second variable in the computer's memory. E) None of the above

C) the variable whose address is stored in the pointer variable.

When you work with a dereferenced pointer, you are actually working with A) a copy of the value pointed to by the pointer variable. B) a variable whose memory has been deallocated. C) the variable whose address is stored in the pointer variable. D) All of the above E) None of the above

B) ++, --

The ________ and ________ operators can respectively be used to increment and decrement a pointer variable. A) dereferencing, indirection B) ++, -- C) modulus, division D) All of the above E) None of the above

B) ampersand ( & )

The ________, also known as the address operator, returns the memory address of a variable. A) exclamation point ( ! ) B) ampersand ( & ) C) percent sign (%) D) asterisk ( * ) E) None of the above

A) int* ptr;.

The code segment int *ptr; has the same meaning as A) int* ptr;. B) int ptr*;. C) int ptr;. D) *int ptr;. E) None of the above

C) is pointing to an object that is still valid after the return of the function.

A function may return a pointer, but the programmer must ensure that the pointer A) has not previously been returned by another function. B) was received as a parameter by the function. C) is pointing to an object that is still valid after the return of the function. D) has been assigned an address. E) None of the above

C) the address of an existing object of the appropriate type.

A pointer may be initialized with A) the value of a floating-point variable. B) the value of a floating-point constant. C) the address of an existing object of the appropriate type. D) All of the above E) None of the above

D) a memory address.

A pointer variable is designed to store A) only floating-point values. B) any legal C++ value. C) an integer. D) a memory address. E) None of the above

A) the address of an existing variable of the appropriate type.

A pointer variable may be initialized with A) the address of an existing variable of the appropriate type. B) any non-zero integer value. C) A and B are both true. D) None of the above

D) A and B are both true.

A reason for passing a pointer to a function is A) to allow the called function to modify a variable accessible to the calling function. B) to avoid the overhead of copying large data structures. C) to allow easy access to data in the function that is being called. D) A and B are both true. E) None of the above

D) cout << &num1;.

A statement that displays the address of the variable num1 is A) cout << &(*num1);. B) cout << num1;. C) cout << *num1;. D) cout << &num1;. E) None of the above

B) use delete afterwards to free the memory allocated by new.

Any time you use the new operator, it is good practice to A) use a preprocessor directive. B) use delete afterwards to free the memory allocated by new. C) clear the data from the old operator D) All of the above E) None of the above

A) adds the value stored in arr[0] to sum.

Assuming that arr is an array identifier, the statement sum += *arr; A) adds the value stored in arr[0] to sum. B) will always result in a compiler error. C) is illegal in C++. D) adds the address of the pointer arr to sum. E) None of the above

A) when a variable is created at run-time.

Dynamic memory allocation occurs A) when a variable is created at run-time. B) when a pointer fails to dereference the right variable. C) when a variable is created by the compiler. D) when a pointer is assigned an incorrect address. E) None of the above

C) address.

Every byte in the computer's memory is assigned a unique A) dynamically allocated value. B) value. C) address. D) name. E) None of the above

A) output the dereferenced value pointed to by p.

If s is a structure variable and p, a pointer, is a member of the structure, the statement cout << *s.p; will A) output the dereferenced value pointed to by p. B) output the value stored in s. C) output the address stored in p. D) result in a compiler error. E) None of the above

C) point to storage allocated by the new operator.

The delete operator should only be used on pointers that A) are appropriately dereferenced. B) have been correctly initialized. C) point to storage allocated by the new operator. D) have not yet been used. E) None of the above

D) stores the keyboard input into the variable pointed to by p.

The statement cin >> *p; A) stores the keyboard input into the pointer called p. B) stores the keyboard input into the variable p. C) is illegal in C++. D) stores the keyboard input into the variable pointed to by p. E) None of the above

A) the memory address of the variable called num1.

The statement cout << &num1; will output A) the memory address of the variable called num1. B) the value stored in the variable called num1. C) the number 1 D) the string "&num1". E) None of the above

D) the value stored in the variable whose address is contained in ptr.

The statement cout << *ptr; will output A) the address of the variable stored in ptr. B) the string "*ptr". C) the address of the variable whose address is stored in ptr. D) the value stored in the variable whose address is contained in ptr. E) None of the above

C) defines a pointer variable called num.

The statement double *num; A) initializes a variable called *num. B) defines a variable of type double called num. C) defines a pointer variable called num. D) defines and initializes a pointer variable called num. E) None of the above

A) sets ptr to point to the allocated memory.

The statement int *ptr = new int; acquires memory to hold an integer and then A) sets ptr to point to the allocated memory. B) initializes the allocated memory to 0. C) assigns an integer value to the variable called ptr. D) creates a new pointer called int. E) None of the above

B) ptr is a pointer variable that will store the address of an integer variable.

The statement int *ptr; means A) the variable called ptr will store an integer value. B) ptr is a pointer variable that will store the address of an integer variable. C) the variable called *ptr will store an asterisk and an integer value. D) All of the above E) None of the above

D) address.

The term pointer can be used interchangeably with A) counter pointer. B) decimal pointer. C) variable. D) address. E) None of the above

C) the structure pointer operator, ->.

To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is A) the dereference operator, <-. B) the ampersand, &. C) the structure pointer operator, ->. D) an asterisk, *. E) None of the above

True

True/False: A pointer can be passed as an argument to a function

True

True/False: A pointer with the value 0 (zero) is called the NULL pointer

True

True/False: An array name is a pointer constant because the address it represents cannot be changed during run-time.

False

True/False: Any arithmetic operation may be performed on pointers.

True

True/False: C++ does not perform array bounds checking.

True

True/False: It is legal to subtract a pointer variable from another pointer variable.

True

True/False: It is possible for a structure to contain as a member a pointer to its own structure type

False

True/False: Memory cannot be allocated after a program is already running.

False

True/False: The ampersand (&) is used to dereference a pointer variable in C++.

True

True/False: The expression *s->p; is only meaningful if s is a pointer to a structure and p is a pointer that is a member of that structure.

True

True/False: The expression s->m has the same meaning as (*s).m.

True

True/False: The expression s->m is meaningful only when s is a pointer to a structure and m is a member of the structure.

True

True/False: The statement Rectangle * boxPtr; defines a variable boxPtr to be a pointer pointing to a type Rectangle.

D) Addition , subtraction , preincrement, and postincrement

Which arithmetic operations can be performed on pointers? A) All arithmetic operations that are legal in C++ B) Only multiplication and addition C) Multiplication, division, addition, and subtraction D) Addition , subtraction , preincrement, and postincrement E) None of the above

D) delete [ ] p;

Which of the following statements correctly deletes a dynamically-allocated array pointed to by p? A) delete array p; B) p delete[ ]; C) delete p; D) delete [ ] p; E) None of the above

E) All of the above are invalid.

Which of the following statements is not valid C++ code? A) float num1 = &ptr2; B) int ptr = int *num1; C) int ptr = &num1; D) All of the above are valid. E) All of the above are invalid.

C) indirectly

With pointer variables, you can ________ manipulate data stored in other variables. A) seldom B) never C) indirectly D) All of the above E) None of the above

D) All of the above

You may use the type pointer to a structure as the type of a A) function parameter. B) function return type. C) structure member. D) All of the above E) None of the above

C) Array names

________ can be used as pointers. A) C++ string objects B) Punctuation marks C) Array names D) All of the above E) None of the above


संबंधित स्टडी सेट्स

ServSafe Quiz 4: The Flow of Food, an Introduction

View Set

Chapter 10: Campaigns and Elections

View Set

L5 Study Guide Questions - Linux Filesystem Administration

View Set

Pharm Final: ENDOCRINE (18 on exam)

View Set

major arterial branches of the descending aorta

View Set

Art Appreciation B Study Questions

View Set

Cost Accounting Exam #1 (Ch. 1-3, 5, 6, 16)

View Set