Why the following code is giving me an error like this
make: *** [all] Segmentation fault (core dumped)
the source code is like this
#include <stdio.h>
int main()
{
int i;
char* ptr = NULL;
*(ptr + 0) = 'H';
*(ptr + 1) = 'e';
*(ptr + 2) = 'l';
*(ptr + 3) = 'l';
*(ptr + 4) = 'l';
*(ptr + 5) = 'o';
for (i = 0; i < 6; i++)
{
printf("%c", *(ptr + i));
}
return 0;
}
But this runs okay
printf("%c", *(ptr + 0));
printf("%c", *(ptr + 1));
printf("%c", *(ptr + 2));
printf("%c", *(ptr + 3));
printf("%c", *(ptr + 4));
printf("%c", *(ptr + 5));