EXERCISES SECTION 2.3.2
Exercise 2.18: Write code to change the value of a pointer. Write code to change the value to which the pointer points.
Exercise 2.19: Explain the key differences between pointers and references.
Exercise 2.20: What does the following program do
- int i = 42;
- int *p1 = &i;
- *p1 = *p1 * *p1;
Exercise 2.21: Explain each of the following definitions. Indicate whether any are illegal and, if so, why.
- int i = 0;
(a) double* dp = &i; (b) int *ip = i; (c) int *p = &i;
Exercise 2.22: Assuming p is a pointer to int, explain the following code:
- if (p)
- if (*p)
Exercise 2.23: Given a pointer p, can you determinewhether p points to a valid object If so, how If not, why not
Exercise 2.24: Why is the initialization of p legal but that of lp illegal
- int i = 42; void *p = &i; long *lp = &i;