Question: What is wrong with this block of code? int *p1 = new int; //line 1 int *p2; //line 2 *p2 = 4; //line 3 p1

What is wrong with this block of code?

int *p1 = new int; //line 1

int *p2; //line 2

*p2 = 4; //line 3

p1 = p2; //line 4 cout << p1 << p2 << endl; //line 5

a. The p2 pointer is not instantiated with the new operator before accessing its memory location on line 3.

b. The p1 pointer is incorrectly instantiated with the new operator before accessing its memory location on line 1. Parentheses are missing from this statement.

c. None of the above.

d. There are no errors in this block of code. A pointer assignment to set the address of a pointer cannot be done with an integer value on line 3.

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 Databases Questions!