Having trouble swapping values in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having trouble swapping values in C++

#include <iostream> using namespace std; int main() { int a = 5; int b = 9; cout << "a: " << a << endl; cout <<"b: " <<b; return 0; }

20th Dec 2020, 12:38 PM
IronCat
IronCat - avatar
1 Answer
+ 5
Just use std::swap(a, b) to swap the values of a and b
20th Dec 2020, 12:45 PM
Aaron Eberhardt
Aaron Eberhardt - avatar