Today I found a syntax thing I had never seen before. Are || and , the same?
bool f() {
cout << "f";
return true;
}
bool g() {
cout << "g";
return true;
}
int main() {
if(f(),g())
{
cout<<"OK with ,";
}
cout<<endl;
if(f()||g())
{
cout<<"OK with ||";
}
return 0;
}
From the output of this program, it seems so:
fgOK with ,
fOK with ||
Are they the same exact thing or are there any little differences?
f(),g()means evaluatef()then evaluateg()and returng()since yourg()returnstrueit is that what is returned toifSo, no, the operators are totally different.
You can see the difference if you modify your function to return
falsefromg(). The conditionf()||g()will still evaluate totruewhilef(),g()will returnfalse.