473,223 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

return function

Hi,I am confused and need the answer of the question mentioned below soon.
return(x,y) is valid?
Can a return() function return more than one value within one statement.

eg:
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<iostream.h>
  3. int sum(int i,int j);
  4. main()
  5. {
  6.  int a,b,k,l;
  7.  char c;
  8.  a=3,b=4;
  9.  k= sum(a,b);
  10.  l=sum(a,b);
  11.  printf("%d %d",k,l);
  12.  c= getchar();
  13.  return 0;    
  14. }     
  15.  
  16. int sum(int i,int j)
  17. {
  18.     int kk,ll;
  19.     kk = i + j;
  20.     ll = i * j;
  21.     return(kk,ll);
  22. }
Earlier I thought compiler should give a compile time error but instead it executed the code and retun 12 12 as the answer.WHY????????
Jan 25 '08 #1
3 1651
Ganon11
3,652 Expert 2GB
, is an operator, just like +, ||, ==, etc. So returning kk, ll actually returns (I think) ll, as the comma operator returns the rightmost expression. Of course, the function isn't returning both kk and ll, it is only returning 1, so there is no reason to ever use the comma operator in a return statement.
Jan 25 '08 #2
hsn
237 100+
very basic and easy.
'return' returns only one variable. no more than that.
you can return an array, vector, int,long.........
anything but only one variable.

GOOD LUCK
Jan 25 '08 #3
Thank you every one...for a quick response...though it was a basic question but i got confussed :(.....never mind thanks a ton
Jan 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: strout | last post by:
function F(e) { return function(){P(e)} } Can anybody tell me what the code is doing? If return another function all in a function I would do function F(e)
10
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
15
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
3
by: Thomas Scheiderich | last post by:
I am curious as to why ASP.NET returns values a different way from VB or VB.net (or can you use both). In my one book I have it returning using a return statement ...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
7
by: nafri | last post by:
hello all, I want to create a function that returns the first element of the Array that is input to it. However, the Input Array can be an Array of points, double, or anyother type, which means...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.