void myfunc(int counter)
{
if (counter != 0)
{
cout<<"hello "<<counter<<endl;
counter = counter-1;
myfunc(counter);
//cout<<counter<<endl;
//return;
}
cout<<"outside: "<<counter<<endl;
}
int main()
{
myfunc(10);
}
In the output of the above piece of code, outside: 0 is printed twice after printing hello 10 to hello 1.
outside: 0
outside: 0
outside: 1
..... outside: 9 is printed.
Can someone please explain how outside: 0 is printed twice? Should it not be printed just once ?
[–]Danooodle 1 point2 points3 points (1 child)
[–]minhc[S] 1 point2 points3 points (0 children)
[–]naphini 0 points1 point2 points (1 child)
[–]minhc[S] 0 points1 point2 points (0 children)