I have a bunch of code like this:
This code does the swapping process as what I precisely needed to swap 2 numbers, however when I need two numbers from the user as follows;Code:#include <iostream> using namespace std; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int main() { int a; int b; a = 7; b = 5; swap(a, b); cout << a << b; return 0; }
the compiler gives me an error about int to int* error which is as expected. Why does the first code do the right swapping although I didn't use the method with & operator?Code:int a; int b; cin >> a; cin >> b; swap(a, b); cout << a <<




Reply With Quote
