輸入三個數,要求使用指針
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c,t;
cin>>a>>b>>c;
int *p1,*p2,*p3;
p1=&a; //將變量a的地址存放到指針變量p1中
p2=&b;
p3=&c;
if(*p1>*p2)
{
t=*p1;
*p1=*p2;
*p2=t;
}
if(*p1>*p3)
{
t=*p1;
*p1=*p3;
*p3=t;
}
if(*p2>*p3)
{
t=*p2;
*p2=*p3;
*p3=t;
}
cout<<*p1<<" "<<*p2<<" "<<*p3<<endl;
return 0;
}
“*”不是指針變量名的一部分。
在變量名前加一個“*”表示該變量是一個指針變量。