Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created October 6, 2012 20:11
Show Gist options
  • Save juanfal/3845963 to your computer and use it in GitHub Desktop.
Save juanfal/3845963 to your computer and use it in GitHub Desktop.
intercambio correcto con paso de parámetros por referencia
// nointercambio.cpp
// juanfc 2012-06-24
//
#include <iostream>
using namespace std;
void intercambio(int& a, int& b)
{
int temp = a;
a = b;
b = temp;
}
int main()
{
int a, b;
cout << "Entrar dos valores a y b: ";
cin >> a >> b;
cout << "Entrados a y b: " << a << " y " << b << endl;
intercambio(a,b);
cout << "Después del intercambio: a y b: "
<< a << " y " << b << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment