1. 程式人生 > >C語言的地址傳遞

C語言的地址傳遞

// struct.cpp : Defines the entry point for the console application.
//

#include 
"stdafx.h"
#include 
<string.h>

int swap(int*a, int*b)
{
    
int temp=0;

    
    temp 
=*b;

    
*=*a;

    
*= temp;

    
return0;

}


int answap(int a,int b)
{
    
int temp=0;

    
    temp 
= b;

    b 
= a;

    a 
= temp;

    
return0;
}


int
 main(int argc, char* argv[])
{
    
int i =2;
    
int j =3;

    answap(i,j);
    printf(
"%d, %d  ",i,j);
    
    swap(
&i,&j);
    printf(
"%d, %d  ",i,j);

    
return0;
}