0

I am just coding and a simple idea (obviously question) comes to my mind that if I have a function like :

int fun1(int p){
  return(p); 
}

and I have a function like this:

int fun1(int p){
  return p; ==> absence of parenthesis
}

so what the difference between those 2?

Ankur Verma
  • 5,793
  • 12
  • 57
  • 93
  • 1
    There's no difference at all, it's just an old convention. http://stackoverflow.com/questions/161879/parenthesis-surrounding-return-values – Solorzano Jose Feb 11 '13 at 06:27
  • 2
    First one with `()` just adds clutter. Majority of Java is coded without unnecessary parentheses. – Steve Kuo Feb 11 '13 at 06:48

4 Answers4

4

No difference. You can decide to use parens if it makes things clearer.

PQuinn
  • 992
  • 6
  • 11
2

It is just a coding convention otherwise NO any differences

subodh
  • 6,136
  • 12
  • 51
  • 73
2

There is zero difference. It's just a redundant way of writing the return-expression.

It dates from some very bad old days of C programming when some people wanted to make return statements look like function calls, or if/while statements.

The fallacy in that was that they aren't function calls or if/while statements.

user207421
  • 305,947
  • 44
  • 307
  • 483
1

Actually no difference between these two its upto you to decide which one you want to use.

Qadir Hussain
  • 1,263
  • 1
  • 10
  • 26