Pointer initialization doubt
- by Jestin Joy
We could initialize a character pointer like this in C.
char *c="test";
Where c points to the first character(t).
But when I gave code like below. It gives segmentation fault.
#include<stdio.h>
#include<stdlib.h>
main()
{
int *i;
*i=0;
printf("%d",*i);
}
But when I give
#include<stdio.h>
#include<stdlib.h>
main()
{
int *i;
i=(int *)malloc(2);
*i=0;
printf("%d",*i);
}
It works( gives output 0).
Also when I give malloc(0), It also works( gives output 0).
Please tell what is happening