Exam 10: Pointers and Dynamic Arrays
Exam 1: C++ Basics37 Questions
Exam 2: Flow of Control33 Questions
Exam 3: Function Basics30 Questions
Exam 4: Parameters and Overloading31 Questions
Exam 5: Arrays32 Questions
Exam 6: Structures and Classes37 Questions
Exam 7: Constructors and Other Tools32 Questions
Exam 8: Operator Overloading,friends,and References31 Questions
Exam 9: Strings37 Questions
Exam 10: Pointers and Dynamic Arrays29 Questions
Exam 11: Separate Compilation and Namespaces35 Questions
Exam 12: Streams and File IO43 Questions
Exam 13: Recursion40 Questions
Exam 14: Inheritance30 Questions
Exam 15: Polymorphism and Virtual Functions34 Questions
Exam 16: Templates27 Questions
Exam 17: Linked Data Structures30 Questions
Exam 18: Exception Handling29 Questions
Exam 19: Standard Template Library46 Questions
Exam 20: Patterns and Uml22 Questions
Select questions type
A pointer is an address,an address is an integer,but a pointer is not an integer.
Free
(True/False)
4.8/5
(43)
Correct Answer:
True
Give three uses for the * operator.Name and describe each use.
Free
(Essay)
4.7/5
(40)
Correct Answer:
Multiplication: x * y
Pointer definition: int *p;
Pointer dereferencing: int x;x = *p;
Pointer parameter declaration: void foo( int * p);
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.
Free
(Essay)
4.7/5
(36)
Correct Answer:
#include <iostream>
using namespace std;
int main()
{
int *entry;
entry = new int[10];
cout << "Enter 10 integers:\n";
for(int i = 0;i < 10;i++)
cin >> entry[i];
for(int i = 0;i < 10;i++)
cout << entry[i] << " ";
cout << endl;
return 0;
}
Why did C++11 introduce the nullptr constant when we already have NULL?
(Essay)
4.8/5
(29)
If a class is named MyClass,what must the destructor be named?
(Multiple Choice)
4.9/5
(37)
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
(Short Answer)
4.8/5
(30)
Dynamic variables or dynamically allocated variables in C++ are created and destroyed according to the program's needs.
(True/False)
4.7/5
(38)
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?
(Essay)
4.9/5
(43)
Pointer variables are just memory addresses and can be assigned to one another without regard to type.
(True/False)
4.9/5
(26)
There should eventually be a call to the operator delete on a pointer that
points to the memory allocated by each call to new.
(True/False)
4.9/5
(42)
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
(Essay)
4.8/5
(29)
A pointer is a variable that holds the address of some other location in memory.
(True/False)
4.9/5
(46)
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.
(Short Answer)
4.8/5
(53)
In deep copy,pointers are followed and data and the pointer structure are duplicated.
(True/False)
4.8/5
(37)
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;
(Short Answer)
4.8/5
(40)
The default copy constructor and default operator = provide deep copy.
(True/False)
4.8/5
(46)
You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the "address-of" operator,&.
(True/False)
4.9/5
(42)
When declaring several pointer variables,there must be one pointer declarator * for each pointer variable.
(True/False)
4.8/5
(46)
Showing 1 - 20 of 29
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)