Hi,
Code:main() { int *p=1,j=1; printf("val of *p:%d\n",*p); //good example for segment fault printf("val of p:%x\n",p); printf("val of &p:%x\n",&p); p = &j; //Introduction of this nullifies seg fault *p = 2; // statement 3 printf("val of p:%x\n",p); printf("Val of p:%d\n",*p); return 0; }
My questions:
1. What is the difference b/w *p=1 in definition and *p=2 in statement 3.
2. Shouldn't both the statements mean one and same? (*p=1 and *p=2);
3. Why is the statement int *p= 1 has p=1 and it is different when it comes to statment *p =3.
Thanks in advance