About GBdirect Consultancy Training Development

Section navigation

Leeds Office (National HQ)

GBdirect Ltd
Leeds Innovation Centre
103 Clarendon Road
LEEDS
LS2 9DF
West Yorkshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

South East Regional Office

GBdirect Ltd
18 Lynn Rd
ELY
CB6 1DA
Cambridgeshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

Please note: Initial enquiries should always be directed to our UK national office in Leeds (West Yorkshire), even if the enquiry concerns services delivered in London or South/East England. Clients in London and the South East will typically be handled by staff working in the London or Cambridge areas.

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

  1. int
    st_eq(const char *s1, const char * s2){
    
      while(*s1 && *s2 && (*s1 == *s2)){
        s1++; s2++;
      }
    
      return(*s1-*s2);
    }
  2. const char *
    find_c(char c, const char *cp){
    
      while(*cp && *cp != c)
         cp++;
      if(*cp)
        return(cp);
    
      return(0);
    }
  3. 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.