Open znichola opened 1 year ago
No, it's not wrong.
In case of doubt, it's good practice to assign in the form ptr = malloc(sizeof(*ptr));
.
The size of the allocation is the size of the data type the pointer points to, not of the pointer itself (which is always 8 bytes).
Dosen't sizeof(*ptr)
mean it's the size of a pointer and not the data type, I had some doubts when I thought about how we malloc for a string str = (char *)malloc(sizeof(char) * len)
ptr is what ptr points to. So if ptr is of type `t_list , then *ptr is of type
t_list`.
it's a bit late, I can't tell if this is wrong so putting it here for later. It feels like it should be a
sizeof(item)