0
Why doesn’t this work
This code should swap the values yet it doesn’t. Can you explain to me what is wrong? https://code.sololearn.com/cVP4egs6Idp8/?ref=app
3 Respuestas
+ 3
Aki Ko you must cout inside the function in order to return the result to the console
now try this code:
#include <iostream>
using namespace std;
void swap(int a, int b){
int temp;
temp = a;
a = b;
b = temp;
cout << a << b;
}
int main() {
int x = 1, y = 2;
swap(x,y);
// cout << x << y; why this????
return 0;
}
+ 1
Because the function doesn't return anything.
You can use pointers for that.