Udun's Labs

Occasional C

When I happen to revisit this slim dinosaur that is C I always have to look up a couple things - here they are for your convenience and mine.

First things first - wrong:

int *ptr = malloc(10 * sizeof (int));


int *ptr = malloc(10 * sizeof *ptr);

NO exceptions. A, yes, sizeof is a unary operator. Are parentheses needed ? Well, I always add them when nobody’s looking.

You might want to visit my sponsors: