Question: Dynamically allocated Arrays Find the errors in the following statements int * p ; * p = 5 ; Delete p; int * p =

Dynamically allocated Arrays
Find the errors in the following statements
int* p ;
*p =5;
Delete p;
int* p = new int;
*p =5;
p = new int;
int* p = new int[10];
int* p =5;
delete p;
int* p = new int[10];
int* q = p;
q[0]=5;
delete p;
delete q;
int n =4;
int* p = &n;
*p =5;
delete p;
Assume that the pointer variable p is declared as follows:
int* p;
carry out the following tasks related to dynamic
allocation.
Initialize p with a pointer to
a dynamically allocated
integer.
Set the allocated integer to
7.
Return the allocated
memory to the heap.
Set up a dynamically
allocated array of length 5.
Fill the last element of the
allocated array 8.
Return the allocated
memory to the heap.
Select all of the following code snippets that are valid
uses of the delete operator.
True False
int n;
int* p = &n;
delete p;
True False
int* p = new int;
delete p;
delete p;
True False
int* p = new int[10];
delete p;
True False
int* p = nullptr;
delete p;
True False
int* p;
*p =5;
True False
int* p = nullptr;
*p =5;
True False
int* p = new int[10];
p[10]=5;
True False
int* p = new int;
p[0]=5;
What do these statement sequences print? If there is a
compiler error, answer error.
int* p = new int;
*p =3;
cout <<*p << endl;
delete p;
int* p = new int[10];
for (int i=0; I <10; i++){
p[i]= i*I;
}
cout <<*p <<<<*(p +1)
<<<< p[2]<< endl;
delete[] p;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!