Connecting Tech Pros Worldwide Help | Site Map

return() syntax

Newbie
 
Join Date: Jul 2006
Posts: 21
#1: Jul 24 '06
Can anyone elaborate the syntax of return()
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,161
#2: Jul 24 '06

re: return() syntax


erm it's faily self explanitory (the parenthisys are optional)

return <Expression>;

<Expression> is the return value of the function (assuming it is not void) and should have a type compatible with return type of the function.
Newbie
 
Join Date: Jul 2006
Posts: 21
#3: Jul 25 '06

re: return() syntax


Quote:

Originally Posted by Banfa

erm it's faily self explanitory (the parenthisys are optional)

return <Expression>;

<Expression> is the return value of the function (assuming it is not void) and should have a type compatible with return type of the function.

Hey,

Thanks for the reply.Scenario with multiple expressions seperated by comma for eg:return(x=2y, y=x*x) something like this where x and y are static variables.
y=x*x will be evaluated ?

Thanks
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,161
#4: Jul 25 '06

re: return() syntax


Quote:

Originally Posted by swapnaoe

Hey,

Thanks for the reply.Scenario with multiple expressions seperated by comma for eg:return(x=2y, y=x*x) something like this where x and y are static variables.
y=x*x will be evaluated ?

Thanks

Why on earth would you want to do this, this is the worst kind of style I can imagine it makes the code hard to understand with absolutely no benefits. Do the calculation on separate lines and then return the required value.

(and I assume by x = 2y you mean x = 2 * y)
Expand|Select|Wrap|Line Numbers
  1. x = 2 * y;
  2. y = x * x;
  3. return y;
  4.  
Newbie
 
Join Date: Jul 2006
Posts: 21
#5: Sep 3 '07

re: return() syntax


Hi,

No I would want to finish the entire code in one line

int x=2,y=3;
return(x=2*y, y=x*x);

it would return 36 and not 4 because the expression in ( ) of return statement evaluates from left to right because of comma operator. That was my intention.

regards
Swapna
Reply