Question: . A pointer variable can contain a pointer to a valid object, a pointer to a deleted object, NULL, or a random value. Write code

. A pointer variable can contain a pointer to a valid object, a pointer to a deleted object, NULL, or a random value. Write code that creates and sets four pointer variables a, b, c, and d to show each of these possibilities. What happens when you dereference each of the four pointers that you created? Write a test program if you are not sure.

#include

void pointer() {

int* a;

int* b;

int* c;

int* d;

int x = 123;

a = &x; int* bObj = new int(456);

b = bObj; delete bObj;

c = NULL;

d = (int*)123456;

}

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!