练习2 指针的学习 看下面的程序,要明确明白为何swap1不起作用,swap2有效.
#include "stdafx.h"
void swap1(int a, int b)
{
int temp = b;
b = a;
a = temp;
}
void swap2(int *a, int *b)
{
int temp = *b;
*b = *a;
*a = temp;
}
int main()
{
int a= 7, b= 8;
swap1(a,b);
printf("swap1 a=%d,b=%d\n",a,b);
swap2(&a,&b);
printf("swap2 a=%d,b=%d\n",a,b);
return 0;
}