Chapter 9

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

The____operator can be used to determine a variable's address.

%(Memory operator)

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

*(indirection)

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

0 or NULL

* operator has 3 uses which are:

1. Multiplication 2 .Definition of a pointer variable= int*ptr; 3. Indirection operator = *ptr=100;

What math operations are allowed on pointers?

1. The ++ or -- operators 2. an integer may be added or subtracted from a pointer variable 3. A pointer may be subtracted from another.

What does int x=7; int*inptr=&x; display when you send *iptr to cout?

7 is displayed

What will the statement display of int number[]={2,4,6,8,10}; cout<<*(number+3)<<endl;

8

What is the purpose of the delete operator?

Free the memory that was created by the new operator

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

It multiplies 4 by the number of bytes for an int then adds it to the memory addresss

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

NEW

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

NULL

The___operator is used to dynamically allocate memory.

New

What is the purpose of the new operator?

Used for Dynamic Memory Allocation to set aside a chunk of memory for a specific data type.

What happens when a program uses the new operator to allocate a block of memory, but the amount of requested memory isn't available?

a. It throws an exception and terminates the program

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

DELETE

What does the indirection operator do?

Dereferences the pointer; allows you to work with the value the pointer is pointing to.

Creating variables while a program is running is called____.

Dynamic Memory Allocations

You can change the address that an array names point to.

F

Array names cannot be dereferenced with the indirection operator.

F.

A pointer variable that has not been initialized is called a null pointer.

F; A null pointer contains the address 0

The *operator is used to get the address of a variable.

F; it is the & operator

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; it should have been used with the new operator, if not unseen things could happen in the program.

Any mathematical operation, including multiplication and division, may be performed on a pointer.

F; only increment/decrements, adding or subtracting of integer, and subtracting a pointer from a pointer

The & symbol is called the indirection operator.

F; the * is the indirection operator; the &is the memory operator

The & operator references a pointer

F; the * operator dereferences a pointer

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

A. The parameter will be initialized with the address that is passed as an argument into it. B. Cannot be changed to point to anything else while the function is executing.

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

A. a pointer to an item that was passed into the function as an argument B. A pointer to a dynamically allocated chunk of memory

Each byte in memory is assigned a unique___

Address

__variables are designed to hold addresses.

Pointer

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

Pointer to a constant- a pointer points to a constant value, it cannot change any values inside the constant. constant pointer- once the pointer is initialized with an address, it cannot point to anything else.

Array names can be used as __ and vice versa.

Pointers

What happens to programs written in older compilers requests a memory that isn't available?

Returns 0 or NULL when it cannot allocate enough memory.

Each byte of memory is assigned a unique address.

T

Pointer variables are designed to hold addresses.

T

Pointers may be compared using the relational operators.

T

THe address operator is not needed to assign an array's address to a pointer.

T

The address 0 is generally considered unusable.

T

The new operator dynamically allocates memory.

T

When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to.

T

When used as function parameters, references variables are much easier to work with than pointers.

T

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.

What does int x=7 int*inptr=&x; display when you send iptr to cout?

The address of x is displayed


Set pelajaran terkait

Biology Mitosis and Meiosis Review

View Set

ACCESS Chapter 1: End of Chapter Quiz, Access Chapter 1, Access Chapter 2, BCIS Review 9

View Set

Management and Organizational Behavior- Ch. 1

View Set

Chapters 16 and 17 Give Me Liberty

View Set

SAS - Base Examination Preparation

View Set

Demand and Supply (How Markets Work)

View Set

Renaissance Inventions & Inventeurs

View Set