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

3rd May 2019, 4:13 PM
Pikachu
Pikachu - avatar
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; }
3rd May 2019, 4:17 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 1
Because the function doesn't return anything. You can use pointers for that.
3rd May 2019, 4:16 PM
raget88
raget88 - avatar