A C declaration codes below int print x and the memory map s

A C++ declaration codes below int *print x; and the memory map shows the following: What will be the values of &p;, p, *p, &x;, and x? Suppose the statements x = 50; p =&x; *p = 38; Then, what will be the values of &p;, p, *p, &x;, and x? After adding the statement of p = &x; What will be the values of &p;, p, *p, &x;, and x? Continuously, after adding the statement of *p = 38; What will be the values of &p;, P, *P, &x;, and x?

Solution

In first scenario:

int *p;

int x;

then , &p will give the address of p i.e = 2000

        p gives you the address in memory where value of *p is located(random memory address same as &x)

     *p gives the value pointed by p(here random value)

&x gives the address pf x(random memory address)

    x is the value stored(some random value)

Scenario 2:

x=50;

&p=2000(address of p)

p=0xbfe8cd5c(some random memory address same as &x)

*p will give some random number because it is not made to point some specific value

&x=0xbfe8cd5c(random memory address)

x=50

when we declare: p=&x;

&p=2000(address of p)

p=0xbfe8cd5c(some random memory address same as &x)

*p=50(value to which it is made to point)

&x=0xbfe8cd5c(random memory address)

x=50

when we write: *p=38

&p=2000(address of p)

p=0xbfe8cd5c(some random memory address same as &x)

*p =38

&x=0xbfe8cd5c(random memory address)

x=38

 A C++ declaration codes below int *print x; and the memory map shows the following: What will be the values of &p;, p, *p, &x;, and x? Suppose the stat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site