Deck 9: Pointers and Dynamic Arrays

ملء الشاشة (f)
exit full mode
سؤال
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.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Even though pointers point to addresses which are integers,you can not assign an integer to a pointer variable.
سؤال
Dynamically created variables have no name.
سؤال
A ___________ is the memory address of a variable.
سؤال
If p1 is an integer pointer variable,with the value of 1000,p1++ changes P1 to point to the memory location 1001.
سؤال
A pointer can be stored in an integer variable.
سؤال
Write the code that assigns to p1 an integer pointer variable)the pointer to a dynamically created integer.
سؤال
In the statement cout << *p1;,the * is called the ________________
سؤال
The & operator is called the _______________
سؤال
You can assign an array to a pointer variable.
سؤال
In the following statement,all the variables are pointers.
int* p1,p2;
سؤال
The size of dynamic arrays must be declared at compile time.
سؤال
Dynamic variables are created at __________
سؤال
When you return a dynamic array to the freestore,you must include the number of elements in the array.
سؤال
Write the code to return the dynamic memory pointed to by p1 to the freestore.
سؤال
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.
سؤال
The size of a dynamic array is defined at ___________
سؤال
int *p1; declares a static variable.
سؤال
Declare a pointer variable named ptr to an integer.
سؤال
Dynamic variables are created from the ___________.
سؤال
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
سؤال
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
سؤال
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.
سؤال
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.
سؤال
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);
سؤال
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;
سؤال
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
سؤال
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
سؤال
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
سؤال
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
سؤال
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;
سؤال
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
سؤال
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;
سؤال
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
سؤال
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
سؤال
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
سؤال
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;
سؤال
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
سؤال
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
سؤال
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
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 9: Pointers and Dynamic Arrays
1
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.
p1 = new string[arraySize];
2
Even though pointers point to addresses which are integers,you can not assign an integer to a pointer variable.
True
3
Dynamically created variables have no name.
True
4
A ___________ is the memory address of a variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
If p1 is an integer pointer variable,with the value of 1000,p1++ changes P1 to point to the memory location 1001.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
A pointer can be stored in an integer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
Write the code that assigns to p1 an integer pointer variable)the pointer to a dynamically created integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
In the statement cout << *p1;,the * is called the ________________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
The & operator is called the _______________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
You can assign an array to a pointer variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
In the following statement,all the variables are pointers.
int* p1,p2;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
The size of dynamic arrays must be declared at compile time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Dynamic variables are created at __________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
When you return a dynamic array to the freestore,you must include the number of elements in the array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
Write the code to return the dynamic memory pointed to by p1 to the freestore.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
The size of a dynamic array is defined at ___________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
int *p1; declares a static variable.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
Declare a pointer variable named ptr to an integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Dynamic variables are created from the ___________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
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);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
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;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.