Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > return from function

Reply
Thread Tools

return from function

 
 
Huub
Guest
Posts: n/a
 
      05-04-2011
Hi,

I made a function that should return 2 integers. But as the compiler
indicates in "return x,y", the x is ignored. So, it is even
possible what I want: returning 2 integers?

Thanks.
 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      05-04-2011
Huub wrote:

> I made a function that should return 2 integers. But as the compiler
> indicates in "return x,y", the x is ignored. So, it is even
> possible what I want: returning 2 integers?


You can only return one thing from a function. But nothing prevents
that thing from being a std:air of integers. The other usual
solution is to pass integers as arguments by reference to the
function.
 
Reply With Quote
 
 
 
 
Joshua Maurice
Guest
Posts: n/a
 
      05-04-2011
On May 4, 1:31*pm, Huub <v.niekerk_@_hccnet.nl> wrote:
> Hi,
>
> I made a function that should return 2 integers. But as the compiler
> indicates in "return x,y", the x is ignored. So, it is even
> possible what I want: returning 2 integers?
>
> Thanks.


"return x,y;" is parsed as a return statement with an expression
"x,y". x and y are names of integer variables. The expression "x,y" is
two expressions "joined" by the comma operator. The comma operator
evaluates the first argument, has a sequence point, then the second
argument. The result of a comma operator is the evaluation of the
second expression.

Note that commas in function calls are not comma operators, and commas
in other contexts are not necessarily comma operators either.
Consider:
f(x, y); //not a comma operator
f((x, y)); //is a comma operator
x, y; //is a comma operator
return x, y; //is a comma operator
int x, y; //not a comma operator
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function doesn't return simply skip the return line hirsh.dan@gmail.com C++ 4 07-22-2008 09:55 AM
Strange Perl line : Return the result of a function to a function AlexHWGUY Perl Misc 5 10-24-2006 09:27 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
getting return value from function without return statement. Seong-Kook Shin C Programming 1 06-18-2004 08:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57