I am starting with test(2,8)
I think the output should be 4 7 Instead I am getting 6 6 4 7 since p1 = p2 i.e. 6 = 6 the cout statement should not be performed. Why am I seeing the 6 6 ?
using namespace std;
void test(int p1, int p2);
void main()
{
test(2, 8);
return ;
}
void test(int p1, int p2)
{
if (p1 != p2)
{
p1 = p1 + 2;
p2 = p2 - 1;
test(p1, p2);
cout << p1;
cout << p2;
}
}
test(p1, p2)is occurring before yourcout << p1andcount << p2that you think might be outputting4 7.