1

Is there any difference between the two? this take the program into two different point or what ,please provide all the detail of it. return is a statement, so why even used return(1)(looking like a function call), please give the detail of 'how it actually works'?.

Anurag Bhakuni
  • 2,379
  • 26
  • 32
  • Although the parentheses are redundant in `return`, some argue that they make a difference in other places, [see here](http://stackoverflow.com/questions/30557710/do-parentheses-make-a-difference-when-determining-the-size-of-an-array) – M.M Aug 12 '15 at 02:49

3 Answers3

2

There is absolutely no difference: parentheses in this context do not mean a function call, they are regular parentheses for enforcing a particular evaluation order (which is completely unnecessary here).

C allows programmers to place parentheses around any expressions, for whatever reason they wish, so compiler interprets both versions of the return in the same way, as long as parentheses are in balance:

return (((((1)))));
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
2

There should be no functional or performance difference at all at run time, since you're either returning the expression 1 or the expression (1), which is the same thing.

It's no different to the following situation, where the statements should have identical run time cost:

int a = 42;
int b = (42);

There's probably the smallest difference at compile time since the compiler has to evaluate more characters in the translation unit but I'd be very surprised if it was noticeable.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • so i would assume () is only preferrable when this is some computation take place ahead of return for more readable of the code . – Anurag Bhakuni Aug 12 '15 at 06:10
  • @Lea-rner, yes, but you'll *never* need it outside the *entire* expression. In other words, while `return 3 * (7 + 12)` may be necessary for an expression where you want to override the order of evaluation, `return (3 * (7 + 12))` will never be. – paxdiablo Aug 12 '15 at 06:20
1

They are equivalent. It's similar to:

1 + 2

is equivalent to:

(1) + (2)

The latter is legal, but the parenthesis is useless.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294