Complete the code to declare a pointer to an integer.
int [1] ptr;The asterisk (*) is used to declare a pointer variable in C++.
Complete the code to assign the address of variable x to pointer ptr.
int x = 10; int* ptr; ptr = [1]x;
The ampersand (&) operator gives the address of a variable.
Fix the error in dereferencing the pointer to get the value of x.
int x = 5; int* ptr = &x; int value = [1]ptr;
The * operator dereferences the pointer to access the value it points to.
Fill both blanks to correctly allocate and assign memory for an integer pointer.
int* ptr = [1] int; *ptr = [2];
Use new int to allocate memory and then assign a value to the dereferenced pointer.
Fill all three blanks to safely delete a dynamically allocated pointer and avoid dangling pointer.
int* ptr = new int(20); delete [1]; [2] = [3];
Use delete ptr; to free memory and then set ptr to nullptr to avoid dangling pointer.
