Chapter 9 C++

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Look at the following array definition. int numbers[] = {2, 4, 6, 8, 10} What will the following statement display? cout << *(numbers + 3) << endl;

8

True or False! When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to

T

True or False! When used as function parameters, reference variables are much easier to work with than pointers.

T

True or False! When you add a value to a pointer, you are actually adding that number times the size of the data type referenced by the pointer.

T

The _____ operator can be used to determine a variable's address.

&

The _____ operator can be used to work with the variable a pointer points to.

*

True or False! The * operator is used to get the address of a variable.

F

True or False! You can change the address that an array name points to.

F

True or False! The new operator dynamically allocates memory.

T

Look at the following code. int x = 7; int *iptr = &x; What will be displayed if you send the expression *iptr to cout? What happens if you send the expression iptr to cout?

*iptr will return the value 7 iptr will return the address

Three different uses for the 8 operator to cout? What happens if you send the expression ptr to cout?

- Multiply, definition of a pointer variable, and the indirection operator

Under what circumstances can you successfully return a pointer from a function?

A pointer to an object that was passed into the function as an argument AND a pointer to a dynamically allocated object

What is the difference between a pointer to a constant and a constant pointer?

A pointer to constant may not be used to change the value it points to.

What math operators are allowed on pointers?

Addition and subtraction

Each byte in memory is assigned a unique _____.

Address

Under older compilers, if the new operator cannot allocate the amount of memory requested it returns _____.

Address 0 or Null

What happens when a program uses the new operator to allocate a block of memory, but the amount of requested memory isn't available? How do programs written with older compilers handle this?

An exception is thrown, which causes th eprogram to terminate. Under older compilers, the new operator returns the null address (address 0) when it cannot allocate the requested amount of memory.

True or False! In using a pointer with the delete operator, it is not necessary for the pointer to have been previously used with the new operator.

F, delete operator is used to free memory that was allocated with new.

What are two advantages of declaring a pointer parameter as a constant pointer?

Declaring a pointer parameter as a constant specify the function can't change what it points to and we can't use to change contents of arguments.

When a program is finished with a chunk of dynamically allocated memory, it should free it with the _____ operator.

Delete

What is the purpose of the new operator?

Dynamically allocate memory

True or False! A pointer variable that has not been initialized is called a null pointer.

F

True or False! Any mathematical operation, including multiplication and division, may be performed on a pointer.

F

True or False! Array names cannot be de-referenced with the indirection operator.

F

True or False! The & operator de-references a pointer

F

True or False! The & symbol is called the indirection operator.

F

Assuming that ptr is a pointer to an int, what happens when you add 4 to ptr?

It adds 4 times the size of an int to the address stored in ptr

What does the indirection operator do?

It de-references a pointer, allowing code to work with the value that the pointer points to.

Creating variables while a program is running is called _____.

Memory allocation

You should only use pointers with delete that were previously used with _____.

New

The _____ operator is used to dynamically allocate memory.

New Operator

A pointer that contains the address 0 is called a _____ pointer.

Null Pointer

_____ variables are designed to hold addresses.

Pointer

Array names can be used as _____, and vice versa.

Pointers

True or False! Each byte of memory is assigned a unique address.

T

True or False! Pointer variables are designed to hold addresses.

T

True or False! Pointers may be compared using the relational operators.

T

True or False! The address 0 is generally considered unusable

T

True or False! The address operator is not needed to assign an array's address to a pointer.

T

What is the purpose of the delete operator?

To free memory that has been dynamically allocated with the new operator.


Kaugnay na mga set ng pag-aaral

Struck-By & Caught-Between Accidents

View Set

Basic Concepts of Sensation and Perception

View Set

Quiz Chapter 6 Thinking and Intelligence (A2)

View Set

ADDING AND SUBTRACTING POLYNOMIALS

View Set

Vocabulary Workshop Level H units 1-6

View Set

Psych - Chapter 28: Child, Older Adult, and Intimate Partner Violence

View Set