C - Arrays of Structures3

From EdWiki

Revision as of 06:51, 7 March 2012 by Jshankar (Talk | contribs) (1 revision)

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

Arrays of Structures ...

Dynamic Allocation

struct Month* pmtab;
pmtab = (struct Month*)malloc(sizeof(struct Month)*NMONTHS);

If p is a pointer to a structure, arithmetic on p takes into account the size of the structure, so p++ incrments p by the correct amount to get the next element of the array of structures.