Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Use integer variable values to transfer, reference and pointer to exchange two numbers, and trace debugging code to understand the difference between pointer and reference.
Use integer variable values to transfer, reference and pointer to exchange two numbers, and trace debugging code to understand the difference between pointer and reference.
# include & ltstdio.h & gt

void swap(int *p 1,int *p2)

{ int t;

t = * p 1; * p 1 = * p2; * p2 = t; //Swap what p 1 and p2 point to.

}

void main()

{ int a,b;

int *pointer_ 1,* pointer _ 2;

Printf ("Please enter two numbers: \ n");

Scanf("%d%d ",&i, & b);

Pointer _1= & a; pointer _ 2 = & ampb;

Swap (pointer _ 1, pointer _ 2); //Function call with pointer as parameter.

printf("\n%d,%d\n ",a,b);

}