When I tried to run this below two codes. For the first one I got segmentation fault error. I don't know why ?
void main() {
int *c1;
*c1=10;
printf("%d\n", *c1);
printf("%d\n", sizeof(c1));
printf("%d\n", sizeof(*c1));
printf("%d\n", c1);
}
When I run this below code, it prints output successfully.
void main() {
int *c1;
*c1=10;
printf("%d\n", *c1);
printf("%d\n", sizeof(c1));
printf("%d\n", sizeof(*c1));
printf("%d\n", c1);
int *c2=c1+1;
printf("%d\n", c2);
printf("%d\n",c2-c1);
}
Can anyone explain the difference? As of understanding, I am assigning the value 10 to the pointer c1 holding address, trying to print the value at c1. So In both it should throw segv error. someone please clarify me