C pointer operation rules



Rules for using Pointer :

  1. Pointer Variable Can be Assigned the address of another Variable
int main() {
     int num = 10;
     int *ptr;
     ptr = #
return(0);
}
  1. Pointer Variable Can be Assigned the value of another Pointer Variable
int *sptr,*tptr;
sptr = #

tptr = sptr;
  1. Pointer Variable Can be initialized with zero or NULL value.
int *sptr,*tptr;
sptr = 0;
tptr = NULL;
  1. Pointer variable Can be Perform Pre/Post fix Increment/Decrement Operation
int arr[20];
int *ptr;
ptr = &arr;
ptr++;
  1. Integer value can be added or Subtracted from Pointer variable
int arr[20];
int *ptr;
ptr = &arr;
ptr = ptr + 2; //arr[2] will be accessed
  1. When two Pointer points to same array then one Pointer variable can be Subtracted from another
  2. Two Pointers pointing to objects of same data type then they can be compared using the Relational Operator
  3. Value cannot be assigned to arbitrary address
int *ptr;
ptr = 100; //Illegal
  1. Pointer Variable cannot be multiplied by Constant
int *ptr;
ptr = ptr * 6; //Illegal