Question: Note: Implement with c++ language. 1) Declare a dynamic array of 50 ints. Declare a dynamic string with the value hello. Write code that results

Note: Implement with c++ language.

1)

Declare a dynamic array of 50 ints.

Declare a dynamic string with the value hello.

Write code that results in a dangling pointer

2)

int* x = new int{7};

cout << *x;

delete x;

cout << x;

cout << *x;

What is the result of each of the print statements above?

  1. an integer value
  2. a memory address
  3. undefined

How should the code above be fixed to prevent a dangling pointer?

3)

void foo() {

int* x = new int{3};

return *x;

}

What is wrong with the above code?

4)

int* x = new int{3};

*x = 8;

int* y = new int{4};

x = y;

What is wrong with the above code?

Thankyou

2)

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!