-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap.cpp
More file actions
47 lines (40 loc) · 998 Bytes
/
swap.cpp
File metadata and controls
47 lines (40 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// **************************
// Program to swap two values
// Now with some differences
// wrote in C++
//
// **************************
// <iostream> instead <stdio.h>
// and using namespace std
#include <iostream>
using namespace std;
// Now it's possible use two differents functions with
// same name
// To pass by reference, it's only use int&, double&
inline void swap(int& i, int& j) {
// pay attention that it's not necessary use pointers
int temp = i;
i = j;
j = temp;
}
// The double swap using the same function name
inline void swap(double& i, double& j) {
double temp = i;
i = j;
j = temp;
}
int main() {
int i, j;
double k, l;
i = 2;
j = 3;
k = 1.5;
l = 4.6;
cout << "i = " << i << " j = " << j << endl;
cout << "k = " << k << " l = " << l << endl;
cout << "----->>> Swapping\n";
swap(i, j);
swap(k, l);
cout << "i = " << i << " j = " << j << endl;
cout << "k = " << k << " l = " << l << endl;
}