These pieces of code cause a segmentation fault:
int *i;
printf("%d\n", *i);
int *i = NULL;
printf("%d\n", *i);
while these do not:
int *i;
i = malloc(sizeof *i);
int *i = NULL;
i = malloc(sizeof *i);
In all examples wild and null pointers dereferenced and passed as an argument to a function which should cause a segmentation fault. Why do the examples using malloc not behave as expected and produce a segmentation fault?