tags:

views:

122

answers:

2
void expand_combinations(const char *remaining_string, string const & s, int rema
in_depth)
{
    if(remain_depth==0)
    {
        std::cout << s << std::endl;
        return;
    }

    for(int k=0; k < strlen(remaining_string); ++k)
    {
        string str(s);
        str.append(1, remaining_string[k]);
        expand_combinations(remaining_string+k+1, str, remain_depth - 1); // what?
    }
    return;
}

On the call to the function, it's passing a string + an integer. What does that become?

+3  A: 

remaining_string is not a string; it's a pointer to a string. Therefore adding an integer to it simply moves the pointer.

For example, if char *blah = "hello", then blah+1 would point to "ello".

houbysoft
+2  A: 

It's passing a pointer to the k+1th character. As it descends into the recursion, each call starts farther and farther into the string.

bmargulies