fork(1) download
  1. #include <iostream>
  2.  
  3. void print_line(int val)
  4. {
  5. for(int i = 0; i < val; ++i)
  6. {
  7. std::cout << " ";
  8. }
  9. std::cout << "This was written by call number " << val << std::endl;
  10. }
  11.  
  12. void recursive_call(int call)
  13. {
  14. print_line(call);
  15.  
  16. if (call < 4)
  17. {
  18. recursive_call(call + 1);
  19. }
  20.  
  21. print_line(call);
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. recursive_call(1);
  28. return 0;
  29. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
 This was written by call number 1
  This was written by call number 2
   This was written by call number 3
    This was written by call number 4
    This was written by call number 4
   This was written by call number 3
  This was written by call number 2
 This was written by call number 1