Rules - Pointer Operation : Perform Programatic Operation using Pointer
Rules for using Pointer :
- Pointer Variable Can be Assigned the address of another Variable
int main() { int num = 10; int *ptr; ptr = # return(0); }
- Pointer Variable Can be Assigned the value of another Pointer Variable
int *sptr,*tptr; sptr = # tptr = sptr;
- Pointer Variable Can be initialized with zero or NULL value.
int *sptr,*tptr; sptr = 0; tptr = NULL;
- Pointer variable Can be Perform Pre/Post fix Increment/Decrement Operation
int arr[20]; int *ptr; ptr = &arr; ptr++;
- 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
- When two Pointer points to same array then one Pointer variable can be Subtracted from another
- Two Pointers pointing to objects of same data type then they can be compared using the Relational Operator
- Value cannot be assigned to arbitrary address
int *ptr; ptr = 100; //Illegal
- Pointer Variable cannot be multiplied by Constant
int *ptr; ptr = ptr * 6; //Illegal
