Quote:
Originally Posted by c_user View Post
see friend as per my logic u cannot assign a no. to a pointer so its showing u the fault....
>>*i=3 is the wrong statement....
hav a gud day...
He is not assigning the int to the pointer. He is actually de-referencing the the pointer with *, and assigning 3 to the address to which the pointer is pointing.

Quote:
Originally Posted by Amar_Raj View Post
Since it is not initialized with valid address and you are accessing that address to modify the value, the segmentation fault occurs! Just allocate some valid address and try... it should work.
Right.
You are de-referencing a pointer which is not assigned to any address.

It's always a good practice to check the pointer b4 assigning values to it. Like this :

Code: C++
void test(int *i) {
  if(i != NULL) { *i = 3; }
  else              { printf("ERROR :: Pointer does not point to a valid address !\n"); }
}