I never quite understand the use of malloc. When I declare some variables, doesn't the system allocate some random memory for them to be placed? In what cases should I use malloc?
I have a struct like this;
Code:
struct Student
{
char name[20];
int number, id, *testmarks;
double total;
};
I am expected to get these values from the user. That's nothing than scanf, but then I am expected to allocate the required memory. What code shoud I write to allocate the required memory for these struct or struct elements? And what will happen if I don't make it?