C pointer function (function & pointer)

C pointer function (function & pointer)

/ * 
 * Function.c 
 * functions used in C 
 * * / 

#include <stdio.h> int NoSwap ( int X, int Y) 
{ / * 
     * function will copy the parameters passed in, so the main different addresses x and y and noswap function of x and y 
     * Accordingly, this does not affect the function and operation of the x and y to the main function of x and y 
     * * / 
    the printf ( " in function noswap : \ n- " ); 
    the printf ( " X value of% d, address P% \ n- " , X, & X); 
    the printf ( " Y value of% d, address P% \ n- " , Y, & Y); int tmp = X; 
    X =


    

     Y;
    y = tmp; 
} 

int the swap ( int * x, int * y) 
{ 
    / * 
     * In this function, the parameter is two pointers, the two main functions stored in the address pointers x and y 
     * Therefore, by two hands, the main function of x and y be exchanged 
     * * / 
    the printf ( " in the swap function: \ n- " ); 
    the printf ( " pointer pointing to the address of x is% p, the value of% d, pointer itself the address P% \ n- " , X, X *, & X); 
    the printf ( " pointer pointing to the address of y is% p, the value of% d, the address pointer itself is P% \ n- " , y, y * , & Y); 

    int tmp = * X;
     * = X * Y;
     * Y = int tmp;
}

 Main ( void ) 
{ 
    int X = . 3 , Y = . 5 ; 

    the printf ( " the main function: \ n- " ); 
    the printf ( " X value of% d, address P% \ n- " , X, & X ); 
    the printf ( " Y value of% d, address P% \ n- " , Y, & Y); 

    NoSwap (X, Y); 
    the printf ( " after NoSwap function, x =% d, y = % d \ n- " , X, Y); 

    swap ( & X, & Y); 
    the printf ( " after swap function,% X = D, Y D =% \ n- " , X, Y); 

    return  0 ; 
}

Guess you like

Origin www.cnblogs.com/noonjuan/p/12070467.html