Quiz 2 - Chapter 9

Ace your homework & exams now with Quizwiz!

The ________ and ________ operators can be used to increment or decrement a pointer variable.

++, --

What will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22

Which of the following statements is not a valid C++ code?

All these are invalid.

Use the delete operator only on pointers that were ________.

Created with the new operator

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

False

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

True

True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.

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.

True

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

True

True/False: In C++ 11, you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

True

Every byte in the computer's memory is assigned a unique

address

The ______, also known as the address operator, returns the memory address of a variable.

ampersand (&)

Look at the following statement: sum += *array++; This statement ________.

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

The statement: int *ptr = nullptr; has the same meaning as ___.

int* ptr = nullptr;

Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer.

multiply, divide

Look at the following code: int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true?

ptr will hold the address of numbers[1]

A function may return a pointer, but the programmer must ensure that the pointer _____.

still points to a valid object after the function ends

The following statement: cin >> *num3;

stores the keyboard input into the variable pointed to by num3

When you work with a dereferenced pointer, you are actually working with ________.

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:

the address of the first byte of storage

If you are using an older compiler that does not support the C+11 standard, you should initialize pointers with _________.

the integer 0, or the value will NULL

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

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

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;

true

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

true

Dynamic memory allocation occurs ________.

when a new variable is created at runtime


Related study sets

Gr 6 Reading Review Part 2 "How Smart are Animals?"

View Set

(3) Chapter 17: Bipolar and Related Disorders *

View Set

Care of Patients with Hypersensitivity (Allergy) and Autoimmunity Ch 20 (Elsevier)

View Set

final, CSE 445 Final Review (Second Half of Semester), 445 Final Exam Review

View Set