C++ final exam

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

________ can be used as pointers. Answers: a. Array names b. Numeric constants c. Punctuation marks d. All of these e. None of these

a. Array names

What will the following code output? int number = 22; int *var = &number; cout << var << endl; Answers: a. The address of the number variable b. 22 c. An asterisk followed by 22 d. An asterisk followed by the address of the number variable

a. The address of the number variable

With pointer variables, you can ________ manipulate data stored in other variables. Answers: a. never b. seldom c. indirectly d. All of these e. None of these

c. indirectly

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; Answers: a. The value stored in the variable whose address is contained in ptr. b. The string "*ptr". c. The address of the variable stored in ptr. d. The address of the variable whose address is stored in ptr. e. None of these

a. The value stored in the variable whose address is contained in ptr.

True/False: A pointer can be used as a function argument, giving the function access to the original argument. Selected Answer: Answers: a. True b. False

a. True

True/False: Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing. cout << myValues[index] << endl; cout << *(myValues+index) << endl; Answers: a. True b. False

a. True

True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array. Answers: a. True b. False

a. True

True/False: In C++ 11, the nullptr key word was introduced to represent the address 0. Selected Answer: a. True b. False

a. True

True/False: To use any of the smart pointers in C++ 11, you must #include the memory header file with the following directive: Answers: a. True b. False

a. True

A function may return a pointer, but the programmer must ensure that the pointer ________. Answers: a. still points to a valid object after the function ends b. has not been assigned an address c. was received as a parameter by the function d. has not previously been returned by another function e. None of these

a. still points to a valid object after the function ends

The contents of pointer variables may be changed with mathematical statements that perform ________. Answers: a. all mathematical operations that are legal in C++ b. multiplication and division c. addition and subtraction d. multiplication and division and addition and subtraction e. None of these

addition and subtraction

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

b. False

What will the following statement output? Answers: a. The value stored in the variable called num1 b. The memory address of the variable called num1 c. The number 1 d. The string "&num1" e. None of these

b. The memory address of the variable called num1

A pointer variable may be initialized with ________. Answers: a. any non-zero integer value b. a valid address in the computer's memory c. an address less than 0 d. any non-zero integer value and an address less than 0 only e. None of these

b. a valid address in the computer's memory

Dynamic memory allocation occurs ________. Answers: a. when a new variable is created by the compiler b. when a new variable is created at runtime c. when a pointer fails to dereference the right variable d. when a pointer is assigned an incorrect address e. None of these

b. when a new variable is created at runtime

A pointer variable is designed to store ________. Selected Answer: Answers: a. any legal C++ value b. only floating-point values c. a memory address d. an integer e. None of these

c. a memory address

When this is placed in front of a variable name, it returns the address of that variable. Selected Answer: Answers: a. asterisk ( * ) b. conditional operator c. ampersand ( & ) d. semicolon ( ; ) e. None of these

c. ampersand ( & )

The following statement: int *ptr = new int; Answers: a. results in a compiler error b. assigns an integer less than 32767 to the variable named ptr c. assigns an address to the variable named ptr d. creates a new pointer named int e. None of these

c. assigns an address to the variable named ptr

Look at the following statement: sum += *array++; Selected Answer: Answers: a. is illegal in C++ b. will always result in a compiler error c. assigns the dereferenced pointer's value, then increments the pointer's address d. increments the dereferenced pointer's value by one, then assigns that value e. None of these

c. assigns the dereferenced pointer's value, then increments the pointer's address

Use the delete operator only on pointers that were ________. Answers: a. never used b. not correctly initialized c. created with the new operator d. dereferenced inappropriately e. None of these

c. created with the new operator

Which of the following statements deletes memory that has been dynamically allocated for an array? Selected Answer: Answers: a. int array = delete memory; b. int delete[ ]; c. delete [] array; d. new array = delete; e. None of these

c. delete [] array;

Look at the following statement: int *ptr = nullptr; In this statement, what does the word int mean? Selected Answer: Answers: a. The variable named *ptr will store an integer value. b. The variable named *ptr will store an asterisk and an integer value. c. ptr is a pointer variable that will store the address of an integer variable. d. All of these e. None of these

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

When you work with a dereferenced pointer, you are actually working with ________. Selected Answer: Answers: a. a variable whose memory has been allocated b. a copy of the value pointed to by the pointer variable c. the actual value of the variable whose address is stored in the pointer variable d. All of these e. None of these

c. the actual value of the variable whose address is stored in the pointer variable

If a variable uses more than one byte of memory, for pointer purposes its address is ________. Answers: a. the address of the last byte of storage b. the average of the addresses used to store the variable c. the address of the first byte of storage d. general delivery e. None of these

c. the address of the first byte of storage

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. Answers: a. the value pointed to by the first is less than the value pointed to by the second b. the value pointed to by the first is greater than the value pointed to by the second c. the address of the first variable comes before the address of the second variable in the computer's memory d. the first variable was declared before the second variable e. None of these

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

What does the following statement do? Double *num2; Selected Answer: d. Declares a pointer variable named num2. Answers: a. Declares a double variable named num2. b. Declares and initializes an pointer variable named num2. c. Initializes a variable named *num2. d. Declares a pointer variable named num2. e. None of these

d. Declares a pointer variable named num2.

Which statement displays the address of the variable num1? Answers: a. cout << num1; b. cout << *num1; c. cin >> &num1; d. cout << &num1; e. None of these

d. cout << &num1;

The statement: int *ptr = nullptr; has the same meaning as ________. Answers: a. int ptr = nullptr; b. *int ptr = nullptr; c. int ptr* = nullptr; d. int* ptr = nullptr; e. None of these

d. int* ptr = nullptr;

The following statement: Answers: a. stores the keyboard input into the variable num3 b. stores the keyboard input into the pointer called num3 c. is illegal in C++ d. stores the keyboard input into the variable pointed to by num3 e. None of these

d. stores the keyboard input into the variable pointed to by num3

When you pass a pointer as an argument to a function, you must ________. Answers: a. declare the pointer variable again in the function call b. dereference the pointer variable in the function prototype c. use the #include<func_ptr.h> statement d. not dereference the pointer in the function's body e. None of these

e. None of these

Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer. Answers: a. multiply, divide b. add, subtract c. +=, -= d. increment, decrement e. None of these

multiply, divide


Ensembles d'études connexes

Module 6 - Chapter 12: Oncologic Management

View Set

Sections 8.1, 8.2, 8.3, 8.4 and 8.5

View Set