malloc(sizeof(int)) vs malloc(sizeof(int *)) vs (int *)malloc(sizeof(int))
I acknowledge that all three of these have a different meaning. But, I don't understand on what particular instances would each of these apply. Can anyone share an example for each of these? Thank you. malloc(sizeof(int)) malloc(sizeof(int *)) (int *)malloc(sizeof(int)) malloc(sizeof(int)) means you are allocating space off the heap to store an int . You are reserving as many bytes as an int requires. This returns a value you should cast to int * . (A pointer to an int .) As some have noted, typical practice in C is to let implicit casting take care of this. malloc(sizeof(int*)) means you are