I'm trying to get my head around C. Reading through K&R, I am flicking back and forth trying to find where it states the situations I should obtain blocks of memory dynamically.
For example, I want to have an int pointer.
int *pointer;
But then K&R states I may want to do:
int *pointer;
pointer = (int*)malloc(sizeof(int));
Essentially, what have I done here that is different? In the first case I created a pointer, that has yet to point to anything, so I guess if the computer runs out of memory and I try to point it to an int value I will have problems. The second case reserves space for my pointer. So I don't have to worry about my program having as many memory problems. Is this correct? If this is correct, shouldn't I use malloc(or calloc) for every pointer I create? Just to make sure my program has fewer issues?