473,406 Members | 2,867 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,406 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 1661
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.