C++ Test 5

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The ___ operator can be used to determine a variables address.

&

Whats the difference between a pointer to a constant and a constant pointer?

A pointer to a constant is a pointer pointing to a constant. A constant pointer points to one thing that cannot be changed.

What math operators are allowed on pointers

Addition & subtraction.

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 and causes it to terminate; returns null address (0).

What does the indirection operator do?

Dereferences a pointer.

___ ___ ___ can allocate storage for a variable or array while a program is running. It stores memory in a 'heap' in the RAM.

Dynamic Memory Allocation (DMA)

Creating variables while a program is running is called ___.

Dynamic memory allocation

(T/F) A pointer variable that has not been initialized is called a null pointer.

False

(T/F) Any mathematical operation, including multiplication and division, may be performed on a pointer.

False

(T/F) Array names cannot be dereferenced with the indirection operator.

False

(T/F) In using a pointer with the delete operator, it is not necessary for the pointer to have been previously used with the new operator.

False

(T/F) Pointers cannot be initialized with the address of an existing object.

False

(T/F) Pointers do not allow you to work with the data they point to.

False

(T/F) The & operator dereferences a pointer.

False

(T/F) The & symbol is called the indirection operator.

False

(T/F) The * operator is used to get the address of a variable.

False

(T/F) You can change the address that an array name points to.

False

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

It moves to the next memory address (1 memory address is 4 bytes.)

___ variables are designed to hold addresses.

Pointer

___ ___ are another way of using a memory address to work with a piece of data.

Pointer Variables

___ are designed to hold memory addresses ONLY, allowing you to indirectly manipulate data stored in other variables.

Pointer variables (pointers)

What is the purpose of the delete operator?

To free dynamically allocated memory (use with new operator)

(T/F) A pointer can be a parameter.

True

(T/F) An array name is really a pointer.

True

(T/F) Because a pointer variable holds an address of another piece of data, it "points" to data as well.

True

(T/F) Memory addresses identify specific locations in a computer's memory.

True

(T/F) Passing arrays as arguments to functions is similar to pointers.

True

(T/F) Pointer variables are designed to hold addresses.

True

(T/F) Pointers are more "low level" than arrays and reference variables.

True

(T/F) Pointers may be compared using the relational operators.

True

(T/F) The address 0 is generally considered unusable.

True

(T/F) The address operator '&' is used to get the address of a variable.

True

(T/F) The address operator is not needed to assign an arrays address to a pointer.

True

(T/F) The new operator dynamically allocates memory.

True

(T/F) The real benefit of pointers is that they allow you to indirectly access and modify the variable being pointed to.

True

(T/F) When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to.

True

(T/F) When used as function parameters, reference variables are much easier to work with than pointers.

True

(T/F) When working with a dereferenced pointer, you're actually working with with the value the pointer is pointing to.

True

(T/F) 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.

True

(T/F) When you add the value of a pointer, you're actually adding that value times the size of the datatype being referenced by the pointer.

True

(T/F)Each byte of memory is assigned a unique address.

True

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

When a pointer points to a dynamically allocated array.

What are the advantages of declaring a pointer parameter such as a constant pointer?

You can't change anything into the new function.

Each byte in memory is assigned a unique ___.

address

Each byte of memory has a unique ___.

address

The ___ returns the memory address of a variable.

address operator (&)

The name of an ___ can be used as a pointer constant.

array

In DMA, the computer returns the address of newly allocated ___ or ___.

arrays; variables

The ___ in front of the variable name indicates that it is a pointer variable.

asterisk (*)

A ___ ___ is a pointer thats initialized with an address and cannot point to anything else.

constant pointer

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

delete

Use ___ to free DMA

delete ('[]' for arrays)

A pointer can be used as a ___ ___, giving the function access to the original argument, much like a reference parameter does.

function parameter

Adresses are displayed in ___.

hexadecimal

The address of a variable is given in ___.

hexadecimal

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

indirection (*)

The asterisk (*) is an ___ ___, which is used to dereference a pointer.

indirection operator

What are three different uses for the * operator?

indirection, multiplication, and declaring pointers.

Definition of a pointer variable:

int *iptr;

The ___ operator is used to dynamically allocate memory.

new

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

new

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

null (0)

When a pointer is set to the address 0, it is referred to as a ___ ___.

null pointer

Array names are ___ ___; you can't make them point to anything but the array they represent.

pointer constants

If you want to store the address of a constant in a pointer, we need to store it in a ___ ___ ___.

pointer-to-constant

a constant pointer to constant is a ___ that points to a ___.

pointer; constant

Array names can be used as __, and vice versa

pointers

Pointers may be compared by using ___ ___.

relational operators (<,>,==,!=,<=,>=)

If there isn't enough memory during DMA, the program will ___.

terminate

What is the purpose of the new operator?

to dynamically allocate memory (use with delete operator)


Set pelajaran terkait

Ethics Chapter 4: The Corporate Culture

View Set

CS281R Final Exam Study Guide -UMKC 2021

View Set

Gero Final Exam "Extra Questions" New Material

View Set

Chapter 7 - Planning and Goal Setting

View Set