The most general form is:
#include <stdio.h>
typedef struct { int a; char b[55]; } Thing;
Thing *p;
p = malloc (100 * sizeof *p);
This works indepentely of the actual definition of Thing
, so if you would "reuse" the line as
Typedef { float water; int fire; } OtherThing;
OtherThing *p;
p = malloc (100 * sizeof *p);
it would still function as intended.
The original case would yield:
char *p;
p = malloc (100 * sizeof *p);
, where the sizeof *p
would of course be superfluous (since sizeof(char) == 1
by definition) , but it won't hurt.
BTW: this answer is mostly about style. Syntactically, all variants are acceptible, given you include stdlib.h (or manually introduce a prototype for malloc())