p = malloc(n * sizeof(*p));rather than the more obvious
p = malloc(n * sizeof(int));(where of course the type we need the size of isn't necessarily int, but rather whatever type it is that p points to[footnote] ). The reason is that the code is more self-contained, more self-documenting, and more robust: a reader looking at
p = malloc(n * sizeof(*p));can see immediately that the correct amont of space is being allocated, without looking back at p's declaration to see what type it is. If p's type ever changes, the malloc call may not have to change.
This page by Steve Summit // Copyright 1995-2004 // feedback