Assume the following declarations int i1 11 i2 22 double d

Assume the following declarations:

            int i1 = 11, i2 = 22;

            double d1 = 3.55, d2 = 6.78;

1. Write declarations for variables p1 and p2 whose values will be addresses of memory locations in which a double can be stored

2. Write a statement to assign the addresses of d1 and d2 to the variables p1 and p2, respectively, in 1, or explain why this is not possible

3. Write a statement to assign the address of i2 to the variable p2 in 1, or explain why this is not possible

4. Write declarations that initialize variables ptr1 and ptr2 with the addresses of i1 and i2, respectively

5. Write a statement that will make variables p1 and p2 of problem 1 point to the same memory location

6. Write a statement that will copy the value stored in the memory location pointed to by ptr2 into the memory location pointed to by ptr1, for ptr1 and ptr2 as in problem 4

7. Write statements that use the variables p1 and p2 of problem 2, but not the variables d1 and d2, to interchange the values of d1 and d2

8. Using typedef, create an alias type CharPointer for pointers to type char.

9. Write a program to determine the address of memory locations allocated to various variables as follows:

Declare two integer variables, two char variables and two double variables and then output the address of each variable (see notes on the next page)

Calculate the size of the memory location allocated to each type by substracting the address of the first variable from the address of the second variable of the same type (see notes on the next page)

Add statements to your program that use the sizeof operator to find the size of the memory location allocated to each type (see notes on the next page)

Solution

1) double *p1,*p2

2)*p1=&d1;

*p2=&d2; this is invalid conversion

this is invalid conversion because we are trying to assain the address to address,

p1=&d1 // correct statement

p2=&d2// correct statement

3) *p2=&i2 // this also gets the same error,

this is invalid conversion because we are trying to assain the address to address,

4) prt1=&i1

ptr2=&i2// assigning address to address of ptr2

Assume the following declarations: int i1 = 11, i2 = 22; double d1 = 3.55, d2 = 6.78; 1. Write declarations for variables p1 and p2 whose values will be address

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site