25 lines
571 B
C
25 lines
571 B
C
#include <stdio.h>
|
|
|
|
// 会交换实参的值
|
|
void swap(int *piA, int *piB)
|
|
{
|
|
// printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
|
|
|
int piC;
|
|
piC = *piA;
|
|
*piA = *piB;
|
|
*piB = piC;
|
|
// printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", piA, piB, *piA, *piB);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int iA = 100, iB = 200;
|
|
printf("first iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
|
|
|
int *piA = &iA, *piB = &iB;
|
|
swap(piA, piB);
|
|
printf("after iA-p: %p, iB-p: %p\n iA: %d,iB: %d\n", &iA, &iB, iA, iB);
|
|
|
|
return 0;
|
|
} |