I'm having a really hard time understanding why we use malloc to get memory instead of just using the regular
int n = 0; way. Typically when we want to make an int, we type
int n; not
int* n = malloc(sizeof(int));. However, in the walkthrough, they write
node* n = malloc(sizeof(node)); instead of
node n;. Is there are reason we can't do the latter?
The answer I've gotten to this question is you need malloc in case you don't know ahead of time how much memory you need. I don't understand when this would be the case. Is Speller one of those times?
My understanding of the "load" function is as follows:
current_word in the dictionary:
Hash it to find the right spot in the table.
Follow the linked list to the end.
Make a new node to contain
current_wordand connect the node to the end of the list.
To me it seems step 3 is doable without malloc. Couldn't we just do something like:
And then have the last node in the linked list point at this new node?