hinafu hinafu - 1 month ago 11x
C++ Question

Returning true or something in bool function

I want to know if, for example, I've got this function:

bool f(...) {
//something here
return true or f(...);

I know it does return
but does it return it without evaluating the other part of the statement or it does evaluate the function again?


No It will not evalue the func() call.

LOGICAL OR evaluates 'Left to Right' and will stop when an expression returns true

you can check it anyway.did you test it?

test it with below program:

#include <iostream>
using namespace std;
bool func();
bool func2();
int main()

bool func2()
cout <<"called me"<<endl;
return true;
bool func()
return (true ||func2());

it will simply execute doesnot print anything to the console.

If you mean the other part of the code in the same function above the return statement,the yes, it will be executed even if the return staement is true at the bottom. if you mean the recursion part,then no it will not be executed since there is true before the call in that statement.if it was return false||func(),only then there will be recursion here.