1.1 Name and illustrate 5 operations that can be applied to pointers.
1.2 Consider
int A, B;
int *Ptr;
int **PtrPtr;
Ptr = &A;
PtrPtr = &Ptr;
a. Is this legal?
b. What are the values of *Ptr and **PtrPtr?
c. Using no other objects besides those declared above, how can we alter
PtrPtr so that it points at a pointer to B without directly touching Ptr?
1.3. Answer the following:
a. Is *&X always equal to X? If not, give an example.
b. Is &*X always equal to X? If not, given an example.
1.4 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
1.5 Give the types of all the identifiers declared here and the types of the expressions. Is any expression illegal?
a. struct S {
int A;
S *B;
};
b. S Z;
c. S *X;
d. S Y[10];
e. S *U[10]
f. X->A
g. X->B
h. Z.B
i. Z.A
j. *Z.A
k. (*Z).A
l. X->B-Z.B
m. Y->A
n. Y[1]
o. Y[1].A
p. Y[1].B
q. U[2]
r. *U[2]
s. U[2]->A
t. U[2]->B
u. U[10]
v. &Z
w. &X
x. U
y. Y
1.6 Draw a picture that illustrates the results after each f the following statements, which are executed sequentially.
int A = 3;
int& B = A;
int& C = B;
B = 5;
C = 2;
1.7 Do you think the following is legal? Why or why not?
int A = 3;
const int& B = A;
1.8 What is wrong with omitting spacing in the following
*X/*Y