1:代碼如下:

// 5.2.cpp : 定義控制台應用程序的入口點。 // #include "stdafx.h" #include <iostream> using namespace std; void main() { int *p1,*p2; int *p; //臨時指針 int a,b; cout << "input a: " << endl; cin >> a; cout << "input b: " << endl; cin >> b; p1=&a;p2=&b; if(a<b) { p=p1; p1=p2; p2=p; } cout << "a=" << a; cout << " "; cout << "b=" << b; cout << endl; cout << "較大的數:" << *p1 << "較小的數: "<< *p2 <<endl; }
運行結果: