CSCI 1 Chapter 9

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The ________ and ________ operators can be used to increment or decrement a pointer variable. ] addition, subtraction ++, -- modulus, division All of these None of these

++, --

The following statement ________. cin >> *num3; -stores the keyboard input in the variable num3 -stores the keyboard input into the pointer num3 is illegal in C++ -stores the keyboard input into the variable pointed to by num3 - None of these

-stores the keyboard input into the pointer num3 is illegal in C++

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i ++) *(numbers + i) = i; cout << numbers[2] << endl; five memory addresses 0 3 2 1

2

What will the following code output? int number = 22; int *var = &number; cout << *var << endl; the address of number 22 an asterisk followed by 22 an asterisk followed by the address of number

22

A pointer variable may be initialized with any nonzero integer value a valid address in the computer's memory an address less than zero any nonzero number None of these

a valid address in the computer's memory

In C++11, the ________ keyword was introduced to represent address 0. a)nullptr b)NULL c)weak_ptr d)shared_ptr e)None of these

a)nullptr

A function may return a pointer but the programmer must ensure that the pointer 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

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

a)the value stored in the variable whose address is contained in ptr

elect all that apply. Select as many of the following options that make this sentence TRUE: The contents of pointer variables may be changed with mathematical statements that perform multiplication division addition subtraction modulus

addition, subtraction

Every byte in the computer's memory is assigned a unique pointer address dynamic allocation name None of these

address

The ________, also known as the address operator, returns the memory address of a variable. astreric(*) ampersand (&) percent(%) exclamation point(!) none of these

ampersand(&)

Which of the following can be used as pointers? array names numeric constants keywords None of these

array name

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

assigns an address to the variable ptr

When you work with a dereferenced pointer, you are actually working with 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) None of these

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

Which of the following is TRUE about this statement? sum += *array++; a)This statement is illegal in C++. b)This statement will cause a compiler error. c)This statement assigns the dereferenced pointer's value, then increments the pointer's address. d)This statement increments the dereferenced pointer's value by one, then assign that value. e)None of these

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

Use the delete operator only on pointers that were 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? a)int array = delete memory; b)int delete[ ]; c)delete [] array; d)new array = delete; e)None of these

c)delete [] array;

In the following statement, what does int mean? int *ptr = nullptr; 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 and will store the address of an integer variable. d)The variable named *ptr will store the value in nullptr. e)None of these

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

When the less than operator (<) is used between two pointer values, the expression is testing whether 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 will the following statement output? a)cout << &num1; b)the value stored in the variable named num1 c)the memory address of the variable named num1 the number 1 d)the string &num1 e)None of these

c)the memory address of the variable named num1 the number 1

What does the following statement do? double *num2; a)Declares a double variable named num2 b)Declares and initializes a pointer variable named num2 c)Initializes a pointer variable named num2 d)Declares a pointer variable named num2 e)None of these

d)Declares a pointer variable named num2

Which of the following statements displays the address of the variable numb? a)cout << numb; b)cout << *numb; c) cin >> &numb; d)cout << &numb; e)None of these

d)cout << &numb;

Which of the following statements is NOT valid C++ code? a)int ptr = &num1; b)int ptr = int *num1; c)float num1 = &ptr2; d)All of these are valid e)All of these are invalid

e)All of these are invalid

The ampersand (&) is used to dereference a pointer variable in C++ -true -false

false

The weak_ptr can share ownership of a piece of dynamically allocated memory. -true -fasle

false

With pointer variables you can access but not modify data in other variables -true -false

false

With pointer variables you can ________ manipulate data stored in other variables. never seldom indirectly All of these None of these

indirectly

Select all that apply. Of the following, which statements have the same meaning? int *ptr = nullptr; int ptr = nullptr; *int ptr = nullptr; int* ptr = nullptr; int ptr* = nullptr;

int *ptr = nullptr; int* ptr = nullptr;

A pointer variable is designed to store any legal C++ value only floating-point values an integer a memory address None of these

memory address

Not all arithmetic operations can be performed on pointers. For example, you cannot ________ or ________ pointers. multiply, divide +=, -= add, subtract increment, decrement None of these

multipy, divide

When you pass a pointer as an argument to a function, you must declare the pointer value again in the function call dereference the pointer value in the function prototype use the #include statement not dereference the pointer in the function's body None of these

none

After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++; ptr will hold the address of numbers[0] ptr will hold the address of the second byte within the element numbers[0] ptr will hold the address of numbers[1] this code will not compile

ptr will hold the address of numbers[1]

To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. null pointer smart pointer dereferenced pointer None of these

smart pointer

What will the following code output? int number = 22; int *var = &number; cout << var << endl; the address of number 22 an asterisk followed by 22 an asterisk followed by the address of number

the address of number

If a variable uses more than one byte of memory, for pointer purposes its address is the address of the last byte of storage the average of all the addresses used to store that variable the address of the first byte of storage the address of the second byte of storage None of these

the address of the first byte of storage

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with the integer 0 or the value NULL the null terminator '\0' a nonzero value Any of these None of these

the integer 0 or the value NULL

A pointer can be used as a function argument, giving the function access to the original argument. -true -fasle

true

An array name is a pointer constant because the address stored in it cannot be changed at runtime. -true -false

true

Assuming myValues is an array of int values and index is an int variable, both of the following statements do the same thing. 1. cout << myValue [index] << endl; 2. cout << *(myValues + index) << endl; -true -false

true

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 -false

true

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 -false

true

In C++11, the nullptr keyword was introduced to represent the address 0. -true -false

true

It is legal to subtract a pointer variable from another pointer variable. -true -false

true

The unique_ptr is the sole owner of a piece of dynamically allocated memory. -true -false

true

To use any of the smart pointers in C++11 you must use the following directive in the header file: -true -false

true

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int? unique_ptr int( new int ); unique_ptr int( new uniq ); unique_ptr uniq( new int ); unique_ptr uniq( new int ); None of these

unique_ptr uniq( new int );

Dynamic memory allocation occurs when a new variable is created by the compiler when a new variable is created at runtime when a pointer fails to dereference the right variable when a pointer is assigned an incorrect address None of these

when a new variable is created at runtime


संबंधित स्टडी सेट्स

Medical-Surgical Nursing Week 2 Part 2

View Set

Luxembourgeois-Questions de base

View Set

AAA Driver's Test Q's: Sample Test #3

View Set

Exam 2 Physical Computing 03/22-04/26

View Set

PN NCLEX- 6th Edition- Adult/Endocrin

View Set

1. Palavras Básicas I (Basic Words)

View Set