fork download
  1. #include <iostream>
  2.  
  3. void swap(int *x, int *y);
  4.  
  5. int main() {
  6. int a, b;
  7. a = 5;
  8. b = 10;
  9. cout << "a = " << a << endl;
  10. cout << "b = " << b << endl;
  11. cout << "&a = " << &a << endl;
  12. cout << "&b = " << &b << endl;
  13.  
  14. swap(a, b);
  15. cout << endl;
  16. cout << "a = " << a << endl;
  17. cout << "b = " << b << endl;
  18.  
  19. return 0;
  20. }
  21.  
  22. void swap(int *x, int *y){
  23. cout << "Hello" << endl;
  24. cout << "x = " << x << endl;
  25. cout << "y = " << y << endl;
  26. int temp;
  27. temp = *x;
  28. *x = *y;
  29. *y =temp;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:9:5: error: ‘cout’ was not declared in this scope
     cout << "a = " << a << endl;
     ^~~~
prog.cpp:9:5: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/6/iostream:61:18: note:   ‘std::cout’
   extern ostream cout;  /// Linked to standard output
                  ^~~~
prog.cpp:9:28: error: ‘endl’ was not declared in this scope
     cout << "a = " << a << endl;
                            ^~~~
prog.cpp:9:28: note: suggested alternative:
In file included from /usr/include/c++/6/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/6/ostream:590:5: note:   ‘std::endl’
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~
prog.cpp:14:14: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
     swap(a, b);
              ^
prog.cpp:3:6: note:   initializing argument 1 of ‘void swap(int*, int*)’
 void swap(int *x, int *y);
      ^~~~
prog.cpp:14:14: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
     swap(a, b);
              ^
prog.cpp:3:6: note:   initializing argument 2 of ‘void swap(int*, int*)’
 void swap(int *x, int *y);
      ^~~~
prog.cpp: In function ‘void swap(int*, int*)’:
prog.cpp:23:5: error: ‘cout’ was not declared in this scope
     cout << "Hello" << endl;
     ^~~~
prog.cpp:23:5: note: suggested alternative:
In file included from prog.cpp:1:0:
/usr/include/c++/6/iostream:61:18: note:   ‘std::cout’
   extern ostream cout;  /// Linked to standard output
                  ^~~~
prog.cpp:23:24: error: ‘endl’ was not declared in this scope
     cout << "Hello" << endl;
                        ^~~~
prog.cpp:23:24: note: suggested alternative:
In file included from /usr/include/c++/6/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/6/ostream:590:5: note:   ‘std::endl’
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~
stdout
Standard output is empty