04 # knowledge pointer

1. What is a pointer? 
{ 
  Pointer is the variable used to store the address 
} 
2. How to use the pointer for calculation? 
{ 
  int a = 10 ;
  int   * p = & a 
  printf ( " % d " , * p);
   * p = 100 ; 
  printf ( " % d " , a); 
} 3. When to use pointers? 
{ 
When the function is passed by value, it can be achieved by passing the pointer 
. The synchronous conversion of the formal parameter and the actual parameter can realize the function 
function more conveniently. 
In addition, the array address ++ operation is not supported in the array, so 
by assigning the first address to Pointer, to achieve the effect of pointer array 
. (Array address can not be changed) 
} 4. What types of pointers are there? 
{ 
Common are:


    $ Pointer variables and pointer arrays corresponding to various data types 
    such as: 
        char * q;
         int   * p;
         short * a;
         long  int * b;
         bool  int * c;
         int rum [ 8 ];         int rum [];
         int * tree ;     int * tree; 
        defines the array of pointers to keep the same amount of array, otherwise it 
        cannot be used. 
    Multi-level pointer: pointer 
        used to store pointer address 
        int ** p = & q; 
        two-dimensional array: pointer can also be regarded as a second-level pointer 
        but not Equal to the second-level array is the second-level pointer  
        so the variable between the first-level pointer and the second-level pointer
        to assign directly
    Array pointer: a pointer used to store the array address 
        int fore [ 10 ];
         int (* poi) [ 10 ] = & fore; 
        where poi + 1 is equal to the address of the fore plus 40; 
    function pointer 
} 
5. Use pointers What are the requirements 
{ 
    the type of the pointer must be 
    strictly consistent with the variable type of the address fetched 
)         
6. Ingenious use of the pointer case 
{ 
        #include <stdio.h> // Summary: the array is defined as a pointer, and the operation is a pointer dereference 
        #define LIM 4
         int sumary ( int a [], int b [], int c []);
         int int main ()
        {
            array1 [LIM] = { 2 , 4 , 6 , 8 };
             int array2 [LIM] = { 1 , 0 , 3 , 6 };
             int array3 [LIM]; 
            sumary (array1, array2, array3); // The first The address is passed into the parameter group 
            int i;
             for (i = 0 ; i <LIM; i ++ ) 
            { 
                printf ( " % d \ n " , array3 [i]); 
            } 

            return  0 ; 
        } 
        int sumary (int a [], int b [], int c []) //
         {
             for ( int i = 0 ; i <LIM; i ++ ) 
            { 
                c [i] = b [i] + a [i]; 
            } 
                
            // return 0;
             // a [] = * (a);
             // * (a + i) = a [i]; 
        } 
}     
7. What are the same items in the pointer and which are different but similar items 
{    
     * The same item 
    array The first address = the address of the first element of the array
     * different items The 
    address of the array! =  Array first address
    Add one to the first address of the array! =Array address plus one 
}

 

Guess you like

Origin www.cnblogs.com/lxuechao/p/12717225.html