Reputation: 1661
I'm looking through a library, and I see this function:
bool CCAPI::IsConnected() const
{
int state;
int res = CCAPIGetConnectionStatus(&state);
return (res == CCAPI_OK) && state;
}
Specifically, what does this last line mean? It looks to me like it's returning two variables as it's using the &&
operator. So what's going on here?
Upvotes: 0
Views: 1549
Reputation: 172864
Operator &&
is Logical AND, could be written as and
too.
The logical operators apply logic functions (NOT, AND, and inclusive OR) to boolean arguments (or types contextually-convertible to bool), with a boolean result.
So the last statement will return the operation result with type bool
.
Upvotes: 0
Reputation: 117856
It is going to return a single bool
, like the function says it will.
The operator &&
is logical AND
, so if res == CCAPI_OK
and state != 0
then it will return true
. In this case state
is being implicitly converted to bool
for the &&
operation.
Upvotes: 5