You can predict your output by following each step manually. In your case, each func
call would work like the following chart:
func(5)
+
+--+ func(4)
| +
| +--+ func(3)
| | +
| | +--+ func(2)
| | | +
| | | +--+ func(1) = 3
| | | |
| | | +--+ func(0) = 2
| | |
| | +--+ func(1) = 3
| |
| +--+ func(2)
| +
| +--+ func(1) = 3
| |
| +--+ func(0) = 2
|
+--+ func(3)
+
+--+ func(2)
| +
| +--+ func(1) = 3
| |
| +--+ func(0) = 2
|
+--+ func(1) = 3
+-----------+
21
solved Output of the following C++ Program [closed]