Anurag Bhakuni
Anurag Bhakuni

Reputation: 2439

what is the difference between return 1 and return(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'?.

Upvotes: 1

Views: 177

Answers (3)

Yu Hao
Yu Hao

Reputation: 122433

They are equivalent. It's similar to:

1 + 2

is equivalent to:

(1) + (2)

The latter is legal, but the parenthesis is useless.

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 882028

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.

Upvotes: 2

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726809

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)))));

Upvotes: 2

Related Questions