Deck 10: Pointers and Dynamic Arrays
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/29
العب
ملء الشاشة (f)
Deck 10: Pointers and Dynamic Arrays
1
Given the definitions,
int *p1,*p2;
p1 = new int;
p2 = new int;
You are to compare and contrast the two assignments.
a)p1 = p2;
b)*p1 = *p2
int *p1,*p2;
p1 = new int;
p2 = new int;
You are to compare and contrast the two assignments.
a)p1 = p2;
b)*p1 = *p2
a)Makes p1 point to the same place in memory to which p2 points.Orphans memory p1 did point to.
b)Makes data where p1 points the same as the data where p2 points.
b)Makes data where p1 points the same as the data where p2 points.
2
In deep copy,pointers are followed and data and the pointer structure are duplicated.
True
3
When declaring several pointer variables,there must be one pointer declarator * for each pointer variable.
True
4
Dangling pointers present no problem in C++
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
5
The default copy constructor and default operator = provide deep copy.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
6
Give three uses for the * operator.Name and describe each use.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
7
A function can return an array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
8
A copy constructor has the same name as the class (let's call it A)and has a parameter that
A)Is call-by value of an A object
B)Is call-by-reference of another class
C)Is call-by-reference of an A class object
D)Is call-by-name of an object named ~A.
E)None of these
A)Is call-by value of an A object
B)Is call-by-reference of another class
C)Is call-by-reference of an A class object
D)Is call-by-name of an object named ~A.
E)None of these
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
9
Give the output from this code fragment:
int *p1,*p2;
p1 = new int;
p2 = new int;
*p1 = 10;
*p2 = 20;
cout << *p1 << " " << *p2 << endl;
*p1 = *p2;
cout << *p1 << " " << *p2 << endl;
*p1 = 30;
cout << *p1 << " " << *p2 << endl;
int *p1,*p2;
p1 = new int;
p2 = new int;
*p1 = 10;
*p2 = 20;
cout << *p1 << " " << *p2 << endl;
*p1 = *p2;
cout << *p1 << " " << *p2 << endl;
*p1 = 30;
cout << *p1 << " " << *p2 << endl;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
10
Pointer variables are just memory addresses and can be assigned to one another without regard to type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
11
If a class is named MyClass,what must the destructor be named?
A)Erase
B)MyClass
C)Any name the programmer wishes except the name of the class
D)~MyClass
E)None of the above.
A)Erase
B)MyClass
C)Any name the programmer wishes except the name of the class
D)~MyClass
E)None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
12
Dynamic variables or dynamically allocated variables in C++ are created and destroyed according to the program's needs.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
13
A pointer is an address,an address is an integer,but a pointer is not an integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
14
An array name is a constant pointer to array base type.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
15
There should eventually be a call to the operator delete on a pointer that
points to the memory allocated by each call to new.
points to the memory allocated by each call to new.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
16
Given the declarations below,write a code fragment that allocates a nameless variable for pointer p1 to point to.
int *p1,*p2;
int *p1,*p2;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
17
Suppose we have the following definitions and assignments:
double *p,v;
p = &v;// p gets the address of v
What is the effect of this assignment?
*p = 99.99
double *p,v;
p = &v;// p gets the address of v
What is the effect of this assignment?
*p = 99.99
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
18
A pointer is a variable that holds the address of some other location in memory.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
19
You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the "address-of" operator,&.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
20
One can use the & operator to extract the value that a pointer points to.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
21
Give the sequence of steps for creating and using a dynamic array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
22
Why did C++11 introduce the nullptr constant when we already have NULL?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
23
Write a type definition for a type called NumberPtr that will be the type for pointer variables that hold pointers to dynamic variables of type double.Also,write a declaration for a pointer variable called myPoint,which is of type NumberPtr.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
24
It is an error to call the delete operator on a pointer a second time.Consider what happens if there is memory allocated on the free store for a class,a destructor,and initializing constructors have been defined,but no copy constructor was defined.Now suppose a function is called that has call-by-value parameters.Why does the program either die in the middle or give a segmentation fault?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
25
Describe the action of the new operator.What does the new operator return? What are the indications of error?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
26
Tell about the freestore (also known as heap).What is put there? How is this done? How does a program access the freestore? What happens to memory that has been allocated but is no longer needed?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
27
Here is the first line of the copy constructor for PFArrayD.The identifier PFArrayD is the name of the class,but in the header it is used three times with different meaning each time.Give the meaning for each use:
PFArrayD::PFArrayD( const PFArrayD& pfaObject)
PFArrayD::PFArrayD( const PFArrayD& pfaObject)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
28
Your program creates a dynamically allocated array as follows:
int *entry;
entry = new int[10];
so that the pointer variable entry is pointing to the dynamically allocated array.Write code to fill this array with 10 numbers typed in at the keyboard.
int *entry;
entry = new int[10];
so that the pointer variable entry is pointing to the dynamically allocated array.Write code to fill this array with 10 numbers typed in at the keyboard.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck
29
Write a type definition for pointer variables that will point to dynamically allocated arrays whose base type is char.The name of the type will be CharArray.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 29 في هذه المجموعة.
فتح الحزمة
k this deck