qfedu-c-level/test/d2.c

25 lines
571 B
C
Raw Normal View History

#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;
}