Deck 10: Characters, C++-Strings, and More About the String Class

ملء الشاشة (f)
exit full mode
سؤال
When you work with a dereferenced pointer, you are actually working with:

A) a variable whose memory has been deallocated
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) All of these
E) None of these
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
A pointer may be initialized with

A) the address of an existing object
B) the value of an integer variable
C) the value of a floating point variable
D) all of these
E) None of these
سؤال
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
سؤال
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
سؤال
The statement int *ptr;
Has the same meaning as

A) int ptr;
B) *int ptr;
C) int ptr*;
D) int* ptr;
E) None of these
سؤال
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
سؤال
Look at the following statement: sum += *array++;
This statement...

A) is illegal in C++
B) will always result in a compiler error
C) assigns the dereferenced pointer's value, then increments the pointer's address
D) increments the dereferenced pointer's value by one, then assigns that value
E) None of these
سؤال
The _________ , also known as the address operator, returns the memory address of a variable.

A) asterisk ( * )
B) ampersand ( & )
C) percent sign (%)
D) exclamation point ( ! )
E) None of these
سؤال
What does the following statement do? double *num2;

A) Declares a double variable named num2.
B) Declares and initializes an pointer variable named num2.
C) Initializes a variable named *num2.
D) Declares a pointer variable named num2.
E) None of these
سؤال
The contents of pointer variables may be changed with mathematical statements that perform:

A) all mathematical operations that are legal in C++
B) multiplication and division
C) addition and subtraction
D) b and c
E) None of these
سؤال
A pointer variable is designed to store

A) any legal C++ value.
B) only floating-point values.
C) a memory address.
D) an integer.
E) None of these
سؤال
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
سؤال
Look at the following statement. int *ptr;
In this statement, what does the word int mean?

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 that will store the address of an integer variable
D) All of these
E) None of these
سؤال
With pointer variables, you can __________ manipulate data stored in other variables.

A) never
B) seldom
C) indirectly
D) All of these
E) None of these
سؤال
When the less than ( < ) operator is used between two pointer variables, 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
سؤال
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 stored in ptr.
D) the address of the variable whose address is stored in ptr.
E) None of these.
سؤال
These can be used as pointers.

A) Array names
B) Numeric constants
C) Punctuation marks
D) All of these
E) None of these
سؤال
When this is placed in front of a variable name, it returns the address of that variable.

A) asterisk ( * )
B) conditional operator
C) ampersand ( & )
D) semicolon ( ; )
E) None of these
سؤال
What will the following statement output? cout << &num1;

A) The value stored in the variable called num1.
B) The memory address of the variable called num1.
C) The number 1.
D) The string "&num1".
E) None of these
سؤال
The ______ and _______ operators can be used to increment or decrement a pointer variable.

A) addition, subtraction
B) modulus, division
C) ++, --
D) All of these
E) None of these
سؤال
The statement cin >> *num3;

A) stores the keyboard input into the variable num3.
B) stores the keyboard input into the pointer called num3.
C) is illegal in C++.
D) stores the keyboard input into the variable pointed to by num3.
E) None of these.
سؤال
When using the new operator with an older compiler, it is good practice to:

A) test the pointer for the NULL address
B) use a preprocessor directive
C) clear the data from the old operator
D) All of these
E) None of these
سؤال
Every byte in the computer's memory is assigned a unique

A) pointer
B) address
C) dynamic allocation
D) name
E) None of these
سؤال
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?

A) ptr will hold the address of numbers[0]
B) ptr will hold the address of the 2nd byte within the element numbers[0]
C) ptr will hold the address of numbers[1]
D) This code will not compile.
سؤال
What will the following code output? int number = 22;
Int *var = &number;
Cout << *var << endl;

A) The address of the number variable
B) 22
C) An asterisk followed by 22
D) An asterisk followed by the address of the number variable
سؤال
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;

A) Five memory addresses
B) 0
C) 3
D) 2
E) 1
سؤال
If a variable uses more than one byte of memory, for pointer purposes its address is:

A) the address of the last byte of storage.
B) the average of the addresses used to store the variable.
C) the address of the first byte of storage.
D) general delivery.
E) None of these.
سؤال
A pointer can be used as a function argument, giving the function access to the original argument.
سؤال
The statement int *ptr = new int;

A) results in a compiler error.
B) assigns an integer less than 32767 to the variable named ptr.
C) assigns an address to the variable named ptr.
D) creates a new pointer named int.
E) None of these
سؤال
A pointer variable may be initialized with

A) any non-zero integer value.
B) any address in the computer's memory.
C) an address less than 0
D) a and c only.
E) None of these.
سؤال
What will the following code output? int number = 22;
Int *var = &number;
Cout << var << endl;

A) The address of the number variable
B) 22
C) An asterisk followed by 22
D) An asterisk followed by the address of the number variable
سؤال
An array name is a pointer constant because the address stored in it cannot be changed during runtime.
سؤال
Which statement displays the address of the variable num1?

A) cout << num1;
B) cout << *num1;
C) cin >> &num1;
D) cout << &num1;
E) None of these
سؤال
A pointer with the value 0 (zero) is called a NULL pointer.
سؤال
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.
سؤال
When you pass a pointer as an argument to a function, you must

A) redeclare the pointer variable in the function call
B) dereference the pointer variable in the function prototype
C) use the #include statement
D) not dereference the pointer in the function's body
E) None of these
سؤال
With pointer variables you can access, but you cannot modify, data in other variables.
سؤال
It is legal to subtract a pointer variable from another pointer variable.
سؤال
Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or __________ a pointer.

A) multiply, divide
B) add, subtract
C) +=, -=
D) increment, decrement
E) None of these
سؤال
Dynamic memory allocation occurs

A) when a new variable is created by the compiler
B) when a new variable is created at runtime
C) when a pointer fails to dereference the right variable
D) when a pointer is assigned an incorrect address
E) None of these
سؤال
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;
سؤال
The ampersand (&) is used to dereference a pointer variable in C++.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 10: Characters, C++-Strings, and More About the String Class
1
When you work with a dereferenced pointer, you are actually working with:

A) a variable whose memory has been deallocated
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) All of these
E) None of these
C
2
A pointer may be initialized with

A) the address of an existing object
B) the value of an integer variable
C) the value of a floating point variable
D) all of these
E) None of these
A
3
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
4
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
5
The statement int *ptr;
Has the same meaning as

A) int ptr;
B) *int ptr;
C) int ptr*;
D) int* ptr;
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
6
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
7
Look at the following statement: sum += *array++;
This statement...

A) is illegal in C++
B) will always result in a compiler error
C) assigns the dereferenced pointer's value, then increments the pointer's address
D) increments the dereferenced pointer's value by one, then assigns that value
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
8
The _________ , also known as the address operator, returns the memory address of a variable.

A) asterisk ( * )
B) ampersand ( & )
C) percent sign (%)
D) exclamation point ( ! )
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
9
What does the following statement do? double *num2;

A) Declares a double variable named num2.
B) Declares and initializes an pointer variable named num2.
C) Initializes a variable named *num2.
D) Declares a pointer variable named num2.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
10
The contents of pointer variables may be changed with mathematical statements that perform:

A) all mathematical operations that are legal in C++
B) multiplication and division
C) addition and subtraction
D) b and c
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
11
A pointer variable is designed to store

A) any legal C++ value.
B) only floating-point values.
C) a memory address.
D) an integer.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
12
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
13
Look at the following statement. int *ptr;
In this statement, what does the word int mean?

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 that will store the address of an integer variable
D) All of these
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
14
With pointer variables, you can __________ manipulate data stored in other variables.

A) never
B) seldom
C) indirectly
D) All of these
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
15
When the less than ( < ) operator is used between two pointer variables, 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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
16
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 stored in ptr.
D) the address of the variable whose address is stored in ptr.
E) None of these.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
17
These can be used as pointers.

A) Array names
B) Numeric constants
C) Punctuation marks
D) All of these
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
18
When this is placed in front of a variable name, it returns the address of that variable.

A) asterisk ( * )
B) conditional operator
C) ampersand ( & )
D) semicolon ( ; )
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
19
What will the following statement output? cout << &num1;

A) The value stored in the variable called num1.
B) The memory address of the variable called num1.
C) The number 1.
D) The string "&num1".
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
20
The ______ and _______ operators can be used to increment or decrement a pointer variable.

A) addition, subtraction
B) modulus, division
C) ++, --
D) All of these
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
21
The statement cin >> *num3;

A) stores the keyboard input into the variable num3.
B) stores the keyboard input into the pointer called num3.
C) is illegal in C++.
D) stores the keyboard input into the variable pointed to by num3.
E) None of these.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
22
When using the new operator with an older compiler, it is good practice to:

A) test the pointer for the NULL address
B) use a preprocessor directive
C) clear the data from the old operator
D) All of these
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
23
Every byte in the computer's memory is assigned a unique

A) pointer
B) address
C) dynamic allocation
D) name
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
24
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?

A) ptr will hold the address of numbers[0]
B) ptr will hold the address of the 2nd byte within the element numbers[0]
C) ptr will hold the address of numbers[1]
D) This code will not compile.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
25
What will the following code output? int number = 22;
Int *var = &number;
Cout << *var << endl;

A) The address of the number variable
B) 22
C) An asterisk followed by 22
D) An asterisk followed by the address of the number variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
26
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;

A) Five memory addresses
B) 0
C) 3
D) 2
E) 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
27
If a variable uses more than one byte of memory, for pointer purposes its address is:

A) the address of the last byte of storage.
B) the average of the addresses used to store the variable.
C) the address of the first byte of storage.
D) general delivery.
E) None of these.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
28
A pointer can be used as a function argument, giving the function access to the original argument.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
29
The statement int *ptr = new int;

A) results in a compiler error.
B) assigns an integer less than 32767 to the variable named ptr.
C) assigns an address to the variable named ptr.
D) creates a new pointer named int.
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
30
A pointer variable may be initialized with

A) any non-zero integer value.
B) any address in the computer's memory.
C) an address less than 0
D) a and c only.
E) None of these.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
31
What will the following code output? int number = 22;
Int *var = &number;
Cout << var << endl;

A) The address of the number variable
B) 22
C) An asterisk followed by 22
D) An asterisk followed by the address of the number variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
32
An array name is a pointer constant because the address stored in it cannot be changed during runtime.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which statement displays the address of the variable num1?

A) cout << num1;
B) cout << *num1;
C) cin >> &num1;
D) cout << &num1;
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
34
A pointer with the value 0 (zero) is called a NULL pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
35
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
36
When you pass a pointer as an argument to a function, you must

A) redeclare the pointer variable in the function call
B) dereference the pointer variable in the function prototype
C) use the #include statement
D) not dereference the pointer in the function's body
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
37
With pointer variables you can access, but you cannot modify, data in other variables.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
38
It is legal to subtract a pointer variable from another pointer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
39
Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or __________ a pointer.

A) multiply, divide
B) add, subtract
C) +=, -=
D) increment, decrement
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
40
Dynamic memory allocation occurs

A) when a new variable is created by the compiler
B) when a new variable is created at runtime
C) when a pointer fails to dereference the right variable
D) when a pointer is assigned an incorrect address
E) None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
41
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
42
The ampersand (&) is used to dereference a pointer variable in C++.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.