I have printed the output from this code but I don't understand why I get such output. Why dont I get 1 only, because from my understanding that the function is called before the cout, so when x is 7 the cout is not excuted instead the function is called with num =6 till num is equal to 1 then the cout will be excuted
#include <iostream>
using namespace std;
void printNum (int num)
{
Sorry I still don't understand. Why It goes to the else statement when the number is 7. I mean 7 is greater than one so it should go in if and the function calls itself again with number 6 without going to the else.
It doesn't. It only calls printNum(6). My modification was just to show you how the code would have to look like to get the expected behaviour you described in the first post.
When printNum(7) is called in your original code it first calls printNum(6) and then it will continue executing the function and print the number 7.