Guest User

Untitled

a guest
Jan 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. void rec(int x)
  2. {
  3. if(x>0)
  4. rec(x--);
  5. printf("%d",x);
  6. }
  7.  
  8. int main()
  9. {
  10. rec(4);
  11. _getch();
  12.  
  13. } /*This doesn't work. And shows a stackoverflow */
  14.  
  15. void rec(int x)
  16. {
  17. if(x>0)
  18. rec(--x);
  19. printf("%d",x);
  20. }
  21.  
  22. int main()
  23. {
  24. rec(4);
  25. _getch();
  26.  
  27. } /*This gives a proper output as expected*/
  28. /*The output is 00123*/
  29.  
  30. void rec(int x) {
  31. if (x>0)
  32. rec(x--);
  33. printf("%d",x);
  34. }
  35.  
  36. int a, b;
  37. a = b = 1;
  38.  
  39. printf("--a: %d b--: %dn", --a, b--); // Output is --a: 0 b--: 1
Add Comment
Please, Sign In to add comment