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?
- an integer value
- a memory address
- 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
Get step-by-step solutions from verified subject matter experts
