Finding the values of pointers


Solve the following:

1. Consider

int a, b;

int *prt; //A pointer
int **prtPrt //A pointer to a pointer

ptr = &a;
prtPtr = &ptr;

a. Is this code legal?

b. What are the values of *ptr and **ptrPtr?

c. Using no other objects besides those already declared, how can you alter ptrPtr so that is points to a pointer to b without directly touching ptr?

d. Is the following statement legal?

2. a. ls *&x always equal to x? If not, give an example

b. ls &*x always equal to x? Uf not, give an example

3. For the declarations
int a = 5;
int *ptr - &a;

what are the values of the following?

a. ptr

b. *ptr

c. ptr == a

d. ptr == &a

e. &ptr

f. *a

g. *&a

h. **&ptr

4 Give the typr of each identifier declared here and the types of the expressions. Is any expression illegal?

a. struct X { inta; S *b; };

b. S z;

c. S *x;

d. x->a

e. x->b

f. z.b

g. z.a

h. *z.a

j. (*z).a

k. x->b-z.b

l. &z

m. &x

5 Is the following code legal? Why or why not?

int a = a;
const in & b = a;

6 What is worng with omitting a space in *x/*y?

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Finding the values of pointers
Reference No:- TGS01937128

Now Priced at $25 (50% Discount)

Recommended (96%)

Rated (4.8/5)