1 build and run the following program showthe output and answer the questions using 5346407

1.    Build and run the following program, showthe output and answer the questions.

using namespace std;

void main()

{

      int i = 7, j = 11;

      printf(“i = %d, j = %dn”, i,j);

      printf(“&i = %p, &j =%pn”, &i, &j);

      // reassign new values…

      i = 4;

      j = 5;

      // reprint…

      printf(“ni = %d, j = %dn”, i,j);

      printf(“&i = %p, &j =%pn”, &i, &j);

}

a.       After the initializationstatement, were we able to change the values of the variables?

b.      After the assignmentstatements, were we able to change the addresses of the variables?Try &i = 4;

c.       Now at the end of main(),add the following statement and try running it: j = &i; Were weable to store the address of i into j?

2.    The following experiment is a review of theprevious experiments. Show the output and answer the questions.

using namespace std;

void main()

{

      char a = 'Q', *pa;

      // the F modifier force the valueto float

      // else by default it is adouble

      float x = 7.3F, *px;

      int i = 2, *m;

      pa = &a;

      px = &x;

      m = &i;

      printf(“pa = %pnpx = %pn m =%pn”, pa, px, m);

}

a.       Out of the six variablesdeclared, which may store addresses?

b.      In the following Figure, showthe values of a, x and i.

c.       From the output, show thevalues of pa, px and m in the Figure below.

d.      Now that you know the values ofpa, px and m, what are the addresses of a, x, and i? Show them inthe Figure.

e.       Must variable that storeaddresses begin with the letter p? If not, how can we tell from thedeclaration of these variables that they can store addresses?

f.       Which variable(s) maystore only (single) characters?

g.      Which variable(s) may storeaddresses to characters?

h.      Can you store the address of afloat in pa? Can you store the address of an integer in pa? If not,what error or warning message is obtained? For example:

pa = &x;

pa = &i;

i.        Can you store acharacter in pa? If not, what error message is obtained?

pa = 'Q';

j.        Can you change theaddress of a variable? If not, what error message is obtained?

&a = 4440;

k.      Try storing the addresses of aand i in px. Does px hold the addresses of floats only?

px = &a;

px = &i;

l.        Try storing theaddresses of a and x in m. Does m hold the addresses of integersonly?

m = &a;

m = &x;

l.        What can you storein a? What can you store in pa? What in their declarationsidentifies the difference?

m.    What can you store in x? What can you storein px? What in their declarations identifies the difference?

"Get 15% discount on your first 3 orders with us"
Use the following coupon
FIRST15

Order Now