News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Operations on Pointer

Started by thiruvasagamani, Sep 22, 2008, 11:25 AM

Previous topic - Next topic

thiruvasagamani

Operations on Pointers:

Rules on pointers:


Here ptr defines as pointer and int define as integer

   1. ptr + ptr = Error
   2. ptr - ptr = Integer
   3. ptr * ptr = Error
   4. ptr / ptr = Error

From the above no arithmetic operations is possible on pointers except subtraction,
ptr - ptr is integer. Number of values between the two address(1005 - 1000 = 5), there
are 5 values between 2 addresses

   1. ptr + int = Ptr
   2. ptr - int = Ptr
   3. ptr * int = Error
   4. ptr / ptr = Error

When we add an integer value to a pointer, result is pointer ( 1000 + 5 = 1005), when we subtract an integer value from a pointer , result is pointer ( (1000 - 5) == 995).

Important points on pointers:

   1. Ptr ++ means move the pointer to next value, ptr -- means move the pointer to preceeding value
   2. Ptr < Ptr , Ptr > Ptr, Ptr = = Ptr we can compare 2 pointers result is true or false
   3. Ptr1 = ptr2 is valid , address is copied from ptr2 to ptr1, that is both pointer ptr1, ptr2 points the same value
Thiruvasakamani Karnan