//指针变量说明中,"*"是类型说明符,表示其后的变量是指针类型。而表达式中出现的"*"则是一个运算符用来表示指针变量所指的变量。
//下面的语句会出现“ The variable 'temp' is being used without being initialized."的错误;
//这说明指针必须要先初始化才可以使用,比如pointer_1和pointer_2
#include "stdio.h"
void swap(int *p1, int *p2)
{
int *temp;
*temp=*p1;
*p1=*p2;
*p2=*temp;
}
void main()
{
int a,b;
int *pointer_1,*pointer_2;
scanf("%d,%d",&a,&b);
pointer_1=&a;
pointer_2=&b;
if (a<b)
swap(pointer_1,pointer_2);
printf("\n%d,%d\n",a,b);
}
用断点可以发现指针变量一开始被赋值为"0xcccccccc“,这个地址是无效地址,不能被直接使用。
//下面是正确的程序,注意swap()的区别:
#include "stdio.h"
void swap(int *p1, int *p2)
{
int temp;
temp=*p1;
*p1