退货还是运营商?

Pat*_*sal 0 c recursion return

我刚看到类似的东西:

return (m(s1 + 1, s2) || m(s1 + 1, s2 + 1));
Run Code Online (Sandbox Code Playgroud)

声明中的||含义是什么return?这m是一个功能; s1并且s2是字符串.

Bar*_*mar 9

||在return声明中使用运算符没什么特别之处.声明如下:

return <expression>;
Run Code Online (Sandbox Code Playgroud)

相当于:

temp = <expression>;
return temp;
Run Code Online (Sandbox Code Playgroud)

(其中temp类型与函数的返回类型相同).

所以你的陈述相当于:

int temp = (m(s1 + 1, s2) || m(s1 + 1, s2 + 1));
return temp;
Run Code Online (Sandbox Code Playgroud)


Mat*_*ieu 5

该行return (m(s1 + 1, s2) || m(s1 + 1, s2 + 1));可以用以下形式重写:

if ( m(s1 + 1, s2) )
{ 
    /* if left part not null, return 1, without 
       evaluationg the right part */
    return 1;
}
else if ( m(s1 + 1, s2 + 1) )
{  
    /* if left was 0, test right part */
    return 1;
}
else
{ 
    /* if both are null, return 0*/
    return 0;
}
Run Code Online (Sandbox Code Playgroud)