Are parentheses around the result significant in a return statement?

前端 未结 11 2356
感情败类
感情败类 2020-11-27 12:07

Is there a difference between these two statements inside a function?

bool returnValue = true;
// Code that does something
return(returnValue);
11条回答
  •  暖寄归人
    2020-11-27 12:24

    They are identical. I see the parenthesis syntax quite often, and I always ask those who use it: why? And none can answer why they use it.

    To bluntly sum it up, parenthesis around returning expressions are used by people who don't quite grasp the difference between function-like macros and functions, or who are confused about the operator precedence or order of evaluation rules in C. There is no coding style benefit from using parenthesis.

    Thus

    return value;
    

    is more correct than

    return (value)
    

    because the latter suggests you don't quite know what you are doing :)

提交回复
热议问题