Page t053, go to NEXT, PREVIOUS, INDEX

const Pointer


Consider

      const float pi = 3.1415;
      float pdq = 1.2345;
      const float *p = π
      float* const d = π    /* WRONG */
      float* const q = &pdq;
      const float *const r = π

      *p = 3.0;    /* WRONG */
      p = &pdq;    /* OK */
      *p = 3.0;    /* still WRONG */

      *q = 3.0;    /* OK */
      q = &pdq;    /* WRONG */

      *r = 3.0;    /* WRONG */
      r = &pdq;    /* WRONG again */

C Course, 22-jan-1997, Peter Klok, pfk@hef.kun.nl