Delicious Digg Facebook Favorites More Stumbleupon Twitter

Friday 21 September 2012

Pointers introduction


   Pointer :- 


·        It is avariable that represents the location of a data item.
·        It can be declared as a variable or an array.
·       They can be used to pass information back and forth between the calling
          and its reference point.
·      They are closely associated with arrays and provide an alternate way to
Access Individual array elements.
 
·      They provide a convenient way to represent multi dimensional arrays.
 
·      They allow a single multidimensional array to be replaced by a lower -          dimensional array of pointers, which permits a group of strings
          to be  represented within a single array, where the individual strings
          may differ in length.

        Declaration of a pointer :-
   
        datatype variablename pointer ;

        example :- 

        int a=10,*p;
        p = address of a;
       *p = value of a;
 
          FUNDAMENTAL CONCEPTS :-
·     Every data item declared occupies one or more continuous memory cells
         in  computer memory.
·     The number of memory cells required to store data item depends on the
         type of the data item.
·     For every identifier that is declared the compiler automatically assigns
         memory cells.
·     The data item can be accessed if we know the location of the first memory
         cell as within a computer the memory cells are numbered consequently.
·     The number associated with each memory cell in  Known as
          as memory  cells  address.
·     The address of memory location is determined by the unary or address       
          operator  “&”, which evaluates the address of the operand.
·      If the address of a memory location is assigned to another variable,
          then  that variable is termed as “Pointer”.
·      A Pointer always holds the address of the memory location but not the value.
·      Therefore the memory location which is holding the address of another     
        memory location is called as pointer variable.
·       
                   
            Value of ‘x’     ------------------------>   Value of ‘y’
 
        Y is a pointer variable to x’s location
                           
          The data represented by the variable ‘x’ can be accessed by the  expression     
         *y  where “*” is a ‘unary operator’  which is called as ‘Indirection operator’, 
       which is used to operate only on a pointer variable.

      The ‘Address Operator’  “&” can act upon the addresses are associated
         with UNIQUE ADDRESSES therefore it cannot operate upon
         ARITHMETIC EXPRESSIONS.
   ·   The Indirection Operator   "*"  can act only upon the OPERANDS that 
         are POINTERS(pointer variable).
   ·    Therefore an indirect reference can appear in place of any ordinary  variable.

                   
          
          
   
 

0 comments:

Post a Comment