When I use code like this :
typedef struct {
int x;
int *pInt;
} tData;
tData *ptData = malloc(sizeof(tData));
If i understand it right, i allocated memory with size of tData
and returned adress to this allocated memory to pointer *ptData
.
But what if i used this code :
typedef struct {
int x;
int *pInt;
} *tData;
If I want to allocate memory to this struct, do I need a struct name? Because for me, if I allocate like malloc(sizeof(*tData));
, it seems to me like I am allocating memory only for the pointer, not for the structure itself. When I want to refer to data in this structure, do I need to use pointer to pointer to a struct?
It confuses me a bit and I couldn't find the answer I am looking for.
Thank you for any explanation!