I am reading Programming: Principles and practice using C++ by Bjarne Stroustrup and I got to chapter 27 where I encountered something fishy. It is this line of code:
struct List* lst = (List*)malloc(sizeof(struct List*));
My question is, shouldn't this be written as:
struct List* lst = (List*)malloc(sizeof(struct List));
When I compile the program with the first version, it works fine, but I have seen malloc being used as the second version.
So my question is, which version is correct and what are the differences?
PS: The book is about C++, but this chapter tries to present a way of writing in C. So this is actually a C program.