fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void exchange (int & lhs, int & rhs) {
  5. int temp = lhs;
  6. lhs = rhs;
  7. rhs = temp;
  8. }
  9.  
  10.  
  11.  
  12. int main() {
  13. int value = 21;
  14. exchange (value, 42);
  15. cout << value << endl;
  16. return 0;
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:14:24: error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'int'
     exchange (value, 42);
                        ^
prog.cpp:4:6: note: in passing argument 2 of 'void exchange(int&, int&)'
 void exchange (int & lhs, int & rhs) {
      ^
stdout
Standard output is empty