How's the result to this 7?

void foo(int i){
if(i>1){foo(i/2);foo(i/2);}cout<<"#"<<endl;}

Recommended Answers

you've written a broken code.

Please change & clarify the code.

Jump to Post

All 2 Replies

you've written a broken code.

Please change & clarify the code.

Putting it in a readable form:

void foo(int i)
{
    if(i>1)
    {
        foo(i/2);
        foo(i/2);
    }
    cout<<"#"<<endl;
}

I don't see where a 7 results, regardless of input. This function doesn't really do anything other than waste time and memory.

What's your real question?

Be a part of the DaniWeb community

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