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?

There is no way for the function to ever get to line 9. It will never display the value of a.

go(2) will return 2.

https://ideone.com/0IhzzH

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.

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 :)

Thanks all of you..!!

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

It means there is no input to fetch from the keyboard.

Okay !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.