Well, if you want to be as clear as possible, consider using this idiom:
It evaluates to the correct size no matter what type p is. And don't worry, that sizeof is a compile-time constant. :)Code:int *p;
p = malloc(10 * sizeof(*p));
Printable View
Well, if you want to be as clear as possible, consider using this idiom:
It evaluates to the correct size no matter what type p is. And don't worry, that sizeof is a compile-time constant. :)Code:int *p;
p = malloc(10 * sizeof(*p));