C - initialize array of structs
Hi, I have a question about this question (but I don't have enough rep to comment on one of the answers).
In the top answer, the one by @pmg, he says you need to do
student* students = malloc(numStudents * sizeof *students);
Firstly, is this equivalent to/shorthand for
student* students = malloc(numStudents * sizeof(*students));
And if so, why do you do sizeof(*students)
and not sizeof(student)
?
No one commented or called him out on it so I'm assuming he's write, and PLEASE go into as much detail as possible about the difference between the two. I'd really like to understand it.