Parenthesis surrounding return values in C

A practical, but unlikely, motive is if you put parenthesis around the value, you can define return as a macro, and then insert some logging code to watch all your returns.


There really isn't a reason...it's just old convention.

To save space, programmers would often do the final math in the return line instead of on it's own line and the parens ensure are mostly there to make it easier to see that it is a single statement that is returned, like this:

return (x+i*2);

instead of

int y = x+i*2;
return y;

The parenthesis became a habit and it stuck.


In the original C specification, parentheses were required around the return value. While modern C compilers and the ANSI C standard do not require them, the presence of parentheses does not affect the return value, and programmers sometimes still include them out of habit, unfamiliarity with the standards, for consistency with a stylistic convention that requires them, or possibly for backward compatibility.

I should add, for people that are thinking about C++: This question is about C and C is not C++; these are two different languages with different standards, capabilities, levels of difficulty, and different styles of usage that emerge -- whatever they have in common, it is wise to treat them as two totally separate things. For a similar question that covers C++, see Are parentheses around the result significant in a return statement?.