Version 1:
int abc(...)
{
if(a || b || c))
return 1;
else
return 0;
}
Version 2:
int abc(...)
{
if(a || b || c))
return 1;
return 0;
}
Is there any difference? Which code is the proper one?
"Is there any difference?"
No.
"Which code is the proper one?"
None. They are equivalent. Note if the else
isn´t explicitly needed for the context, omit it since it is redundant:
Unnecessary 'else' after 'return'. (No-else-return)
Note: The linked question is for Javascript, but it shares the same concern of yours.
Furthermore, your code could be simplified:
int abc (...)
{
return (a || b || c);
}
If the condition is true 1
, else 0
is returned.