00001 00018 #include <iostream> 00019 using namespace std; 00020 00021 void intercambia(int a, int b) 00022 { 00023 int aux=a; 00024 a= b; 00025 b= aux; 00026 } 00027 void intercambia(int *a, int *b) 00028 { 00029 int *aux=a; 00030 a= b; 00031 b= aux; 00032 } 00033 00034 int main() 00035 { 00036 int var1= 1; 00037 int var2= 2; 00038 00039 int &ref1= var2; 00040 int &ref2= var1; 00041 00042 int *p1= &var1; 00043 int *p2= &var2; 00044 00045 int *pref1= &ref1; 00046 int *pref2= &ref2; 00047 00048 cout << " ---- Valores iniciales:" << endl; 00049 cout << "Los valores de var1,var2 son: "<<var1 << " " << var2 << endl; 00050 cout << "Los valores de ref1,ref2 son: "<<ref1 << " " << ref2 << endl; 00051 cout << "Los valores de p1,p2 son:" << p1 << " " << p2 << endl; 00052 cout << "Los valores de pref1,pref2 son:" << pref1 << " " << pref2 << endl; 00053 00054 cout << " ---- Intercambio de (var1,var2) y (p1,p2)" << endl; 00055 00056 intercambia(var1,var2); 00057 intercambia(p1,p2); 00058 00059 cout << " ---- Valores Finales:" << endl; 00060 cout << "Los valores de var1,var2 son: "<<var1 << " " << var2 << endl; 00061 cout << "Los valores de ref1,ref2 son: "<<ref1 << " " << ref2 << endl; 00062 cout << "Los valores de p1,p2 son:" << p1 << " " << p2 << endl; 00063 cout << "Los valores de pref1,pref2 son:" << pref1 << " " << pref2 << endl; 00064 00065 00066 return 0; 00067 }