I need to find out the output of the following code snippet return by function go(2) ...

int a=10;
int go(int b)
    {
        if(b<=4)
        return b;
        else 
        return go(b+1)*go(b-2)-(b*2);

        ++a;
        cout<<a;

        return -1;
    }

When I do the dryrun myself on paper , it should first return the value of b from the line no. 5 and the display value of a in line no. 10 but when I execute the code in compiler it shows none with the returning value 0(obviously which i write in main())...can u please tell me why?

go(2) didn't continue past line 5. You may want to refresh your memory about return(). An accepted explanation is "The keyword return causes the function to exit, passing control back to the calling function."

Lines 8-12 will never be executed with the code you have. In your function you have:

if(b<=4)
    return b;
else 
    return go(b+1)*go(b-2)-(b*2);

So if b <= 4 then you return b;. is be is anything else then you return go(b+1)*go(b-2)-(b*2);. Anything after the if will never be executed as both paths out of the if statement exit the function.

Edited 1 Year Ago by NathanOliver

Oh wao Moschops I didn't know this Question was taken from internet.
I was solving my past papers to practice. There I found it :)

But in this link ... "Standard input is empty " is written ..what does that mean? o_o

This question has already been answered. Start a new discussion instead.