Actions

EmSys

C - Address arithmetic

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Address arithmetic

  • If p is a pointer to some element of an array, then p++ increments p to point to the next element, and p += i increments it to point i elements beyond where it currently does.
  • A pointer and an integer may be added or subtracted.
  • It is not legal to add two pointers, or to multiply or divide or shift or mask, or to add float or double.
  • It is illegal to assign a pointer of one type to a pointer of another type without a cast.
  • If p and q point to members of the same array, then subtraction is valid, e.g.,
q - (p+1) is the number of elements from p to q.
  • If p and q point to members of the same array, then relations like ==, !=, <, >, etc., work properly.
  • Any pointer can be meaningfully compared for equality or inequality with zero.