Chapter 5
Exercise 5.1
0-9
.
Exercise 5.2
Nothing. It is guaranteed to be a valid address and can be used to check a pointer against the end of the array.
Exercise 5.3
Only when they point into the same array, or to the same object.
Exercise 5.4
It can safely be used to hold the value of a pointer to any sort of object.
Exercise 5.5
-
int st_eq(const char *s1, const char * s2){ while(*s1 && *s2 && (*s1 == *s2)){ s1++; s2++; } return(*s1-*s2); }
-
const char * find_c(char c, const char *cp){ while(*cp && *cp != c) cp++; if(*cp) return(cp); return(0); }
-
const char * sub_st(const char *target, const char *sample){ /* * Try for a substring starting with * each character in sample. */ while(*sample){ const char *targ_p, *sample_p; targ_p = target; sample_p = sample; /* string compare */ while(*targ_p && *sample_p && (*targ_p == *sample_p)){ targ_p++; sample_p++; } /* * If at end of target, have substring! */ if(*targ_p == 0) return(sample); /* otherwise try next place */ sample++; } return(0); /* no match */ }
Exercise 5.6
No answer can be given.