The code below is my book and I need to trace its execution, showing the stack frame
created for each recursive call, the values stored in the stack frame, and the value returned. Where I am confused is in line 17 behead(s+1,n-1) because s is a string variable so how it is possible to add it an integer. I could not run this code because of this detail.
#define Z 3
string behead( string s, int n );
int main( void )
{
string answer;
char word[] = "distrust";
printf( "\nBeheading the victim: %s?\n", word );
answer = behead( word, Z );
printf( "Now: %s!\n\n", answer );
}
string behead( string s, int n )
{
if (n == 0) return s;
else return behead( s + 1, n - 1 );
}
#include <cstdio>,#include <string>andusing namespace std;? Apart from that, I can tell you what this will do: not compile, as std::string has nooperator +(int)that I'm aware of, assuming you're using std::string. If you're not, we can't answer this without knowing the definition of what yourstringclass is.