Deck 9: Pointers and Dynamic Arrays
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/39
العب
ملء الشاشة (f)
Deck 9: Pointers and Dynamic Arrays
1
If p1 is an integer pointer variable, with the value of 1000, p1++ changes P1 to point to the memory location 1001.
False
2
Which of the following correctly declare 3 integer pointers?
A) int* p1, p2, p3;
B) int *p1, p2, p3;
C) int *p1, *p2, *p3;
D) all of the above.
A) int* p1, p2, p3;
B) int *p1, p2, p3;
C) int *p1, *p2, *p3;
D) all of the above.
C
3
Write the code to return the dynamic memory pointed to by p1 to the freestore.
delete p1;
4
A pointer can be stored in an integer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
5
Write the code to declare a dynamic array of strings use the string pointer variable p1) that has as many elements as the variable arraySize.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
6
Declare a pointer variable named ptr to an integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
7
When you return a dynamic array to the freestore, you must include the number of elements in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
8
If p1 and p2 are both pointers that point to integers in memory, the condition p1==p2 will be true if the values that are in those memory locations are the same.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
9
Write the code that assigns to p1 an integer pointer variable) the pointer to a dynamically created integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
10
Dynamic variables are created at __________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
11
A ___________ is the memory address of a variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
12
Dynamic variables are created from the ___________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
13
The size of dynamic arrays must be declared at compile time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
14
int *p1; declares a static variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
15
The & operator is called the _______________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
16
Even though pointers point to addresses which are integers, you can not assign an integer to a pointer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
17
Dynamically created variables have no name.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
18
The size of a dynamic array is defined at ___________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
19
In the statement cout << *p1;, the * is called the ________________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
20
You can assign an array to a pointer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
21
If p1 is an integer pointer that is pointing to memory location 1001, and an integer takes 4 bytes, then p1+1) evaluates to:
A) 1002
B) 1004
C) 1005
D) Unknown
A) 1002
B) 1004
C) 1005
D) Unknown
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
22
What is the output of the following code fragment?
Int v1=2, v2=-1, *p1, *p2;
P1 = & v1;
P2= & v2;
P2=p1;
Cout << *p2 << endl;
A) 2
B) -1
C) -2
D) 1
Int v1=2, v2=-1, *p1, *p2;
P1 = & v1;
P2= & v2;
P2=p1;
Cout << *p2 << endl;
A) 2
B) -1
C) -2
D) 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
23
Given that a typedef for IntPtr defines a pointer to an integer, what would be the correct declaration for a function that expects a reference to an integer pointer?
A) void f1 IntPtr& ptr);
B) void f1 IntPtr&* ptr);
C) void f1 IntPtr*& ptr);
D) All of the above
A) void f1 IntPtr& ptr);
B) void f1 IntPtr&* ptr);
C) void f1 IntPtr*& ptr);
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
24
Which of the following correctly declares a dynamic array of strings?
A) p1 = new string13);
B) p1 = new string[];
C) p1 = new string[13];
D) p1 = new stringArray13);
A) p1 = new string13);
B) p1 = new string[];
C) p1 = new string[13];
D) p1 = new stringArray13);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
25
What is the output of the following code?
Int *p1, *p2;
P1 = new int;
P2 = new int;
*p1=11;
*p2=0;
P2=p1;
Cout << *p1 <<" " << *p2 << endl;
A) 11 0
B) 0 11
C) 11 11
D) 0 0
Int *p1, *p2;
P1 = new int;
P2 = new int;
*p1=11;
*p2=0;
P2=p1;
Cout << *p1 <<" " << *p2 << endl;
A) 11 0
B) 0 11
C) 11 11
D) 0 0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
26
Given that p1 is a pointer variable of the string class, which of the following are legal statements?
A) p1 = new int;
B) cout << *p1;
C) p1 = new char[10];
D) *p1 = new string;
E) B and D
A) p1 = new int;
B) cout << *p1;
C) p1 = new char[10];
D) *p1 = new string;
E) B and D
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
27
Which of the following is not true?
A) a pointer can be assigned the address of an array
B) an array can be assigned the value in a pointer variable
C) if a pointer points to an array, it can be used in place of the array name
D) if a pointer points to an array, the pointer does not know how many elements are in the array.
A) a pointer can be assigned the address of an array
B) an array can be assigned the value in a pointer variable
C) if a pointer points to an array, it can be used in place of the array name
D) if a pointer points to an array, the pointer does not know how many elements are in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
28
What is the output of the following code fragment?
Float *p1;
P1 = new float3);
Cout << *p1;
A) 3.0
B) unknown, the address p1 points to is not initialized
C) unknown, the code is illegal, p1 points to a dynamic array
D) 0.0
Float *p1;
P1 = new float3);
Cout << *p1;
A) 3.0
B) unknown, the address p1 points to is not initialized
C) unknown, the code is illegal, p1 points to a dynamic array
D) 0.0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
29
Given that p1 is an integer pointer variable, and a1 is an integer array, which of the following statements are not legal code?
A) p1= a1;
B) cout << p1[0];
C) cin >> p1[0];
D) a1 = p1;
A) p1= a1;
B) cout << p1[0];
C) cin >> p1[0];
D) a1 = p1;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
30
If a program requires a dynamically allocate two-dimensional array, you would allocate the memory by using
A) p1 = new int*[numRows]; forint i=0; i < numRows; i++)
P1[i] = new int[numColumns];
B) p1 = new int*[numRows][numColumns];
C) p1 = new[numRows][numColumns]int;
D) none of the above
A) p1 = new int*[numRows]; forint i=0; i < numRows; i++)
P1[i] = new int[numColumns];
B) p1 = new int*[numRows][numColumns];
C) p1 = new[numRows][numColumns]int;
D) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
31
What is wrong with the following code fragment?
Int *p1, *p2;
P1 = new int;
P2 = new int;
*p1=11;
*p2=0;
P2=p1;
Cout << *p1 <<" " << *p2 << endl;
Delete p1;
Delete p2;
A) nothing
B) p1 and p2 both have the same value, so the delete p2 will cause an error
C) You have a memory leak.
D) B and C
Int *p1, *p2;
P1 = new int;
P2 = new int;
*p1=11;
*p2=0;
P2=p1;
Cout << *p1 <<" " << *p2 << endl;
Delete p1;
Delete p2;
A) nothing
B) p1 and p2 both have the same value, so the delete p2 will cause an error
C) You have a memory leak.
D) B and C
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
32
Assuming that the pointer variable p1 is of the correct type and size is an integer with some value > 1, which of the following declarations are legal?
A) p1 = new string[size];
B) p1 = new ifstream[size];
C) p1 = new char[size*size];
D) A and B
E) A, B and C
A) p1 = new string[size];
B) p1 = new ifstream[size];
C) p1 = new char[size*size];
D) A and B
E) A, B and C
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
33
Which of the following statements correctly prints out the value that is in the memory address that the pointer p1 is pointing to?
A) cout << &p1;
B) cout << p1;
C) cout << int* p1;
D) cout << *p1;
A) cout << &p1;
B) cout << p1;
C) cout << int* p1;
D) cout << *p1;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
34
Given that p1 is a pointer, p1++
A) always causes a run time error
B) advances p1 by one unit of the type of variable to which p1 points
C) adds 1 to whatever p1 is pointing to
D) adds one element to the array that p1 is pointing to
A) always causes a run time error
B) advances p1 by one unit of the type of variable to which p1 points
C) adds 1 to whatever p1 is pointing to
D) adds one element to the array that p1 is pointing to
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following correctly declares a user-defined data type that defines a pointer to a float?
A) float* floatPtr ;
B) typedef float* floatPtr;
C) typedef floatPtr *float;
D) typedef floatPtr* float
A) float* floatPtr ;
B) typedef float* floatPtr;
C) typedef floatPtr *float;
D) typedef floatPtr* float
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
36
If two pointer variables point to the same memory location, what happens when one of the pointers is freed?
A) The other pointer should be considered to be un-initialized
B) The other pointer still points to a valid memory address
C) If you attempt to free the other pointer a run-time error will occur.
D) All of the above
E) A and C
A) The other pointer should be considered to be un-initialized
B) The other pointer still points to a valid memory address
C) If you attempt to free the other pointer a run-time error will occur.
D) All of the above
E) A and C
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
37
In which case would you consider using a dynamic array?
A) If the array is small, and the size is known before the program runs.
B) If the program needs to get the size of the array from the user
C) If the array size is big, but known at compile time
D) You should always use a dynamic array
A) If the array is small, and the size is known before the program runs.
B) If the program needs to get the size of the array from the user
C) If the array size is big, but known at compile time
D) You should always use a dynamic array
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
38
Which of the following assigns to p1 the pointer to the address of value?
A) *p1=&value;
B) p1=value;
C) p1=&value;
D) &p1 = *value;
A) *p1=&value;
B) p1=value;
C) p1=&value;
D) &p1 = *value;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck
39
Which of the following statements correctly returns the memory from the dynamic array pointer to by p1 to the freestore?
A) delete [] p1;
B) delete p1[];
C) delete *p1;
D) delete p1;
A) delete [] p1;
B) delete p1[];
C) delete *p1;
D) delete p1;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 39 في هذه المجموعة.
فتح الحزمة
k this deck