fork(2) download
  1. #include <iostream>
  2.  
  3. void foo(int a, int b, int c = -1) {
  4. std::cout << "foo(" << a << ", " << b << ", " << c << ")\n";
  5. }
  6.  
  7. int main() {
  8. foo(1, 2); // output: foo(1, 2, -1)
  9.  
  10. // error: does not use default from surrounding scope
  11. //void foo(int a, int b = 0, int c);
  12.  
  13. void foo(int a, int b, int c = 30);
  14. foo(1, 2); // output: foo(1, 2, 30)
  15.  
  16. // error: we cannot redefine the argument in the same scope
  17. // void foo(int a, int b, int c = 35);
  18.  
  19. // has a default argument for c from a previous declaration
  20. void foo(int a, int b = 20, int c);
  21. foo(1); // output: foo(1, 20, 30)
  22.  
  23. void foo(int a = 10, int b, int c);
  24. foo(); // output: foo(10, 20, 30)
  25.  
  26. {
  27. // in inner scopes we can completely redefine them
  28. void foo(int a, int b = 4, int c = 8);
  29. foo(2); // output: foo(2, 4, 8)
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
foo(1, 2, -1)
foo(1, 2, 30)
foo(1, 20, 30)
foo(10, 20, 30)
foo(2, 4, 8)