can a function return two values?:confused:
Printable View
can a function return two values?:confused:
No Java does not allow returning multiple values. Only one value can be returned by a method in Java. Also one more additional thing to know in Java regarding passing of value to methods is everything in Java is passed by value.
Not only in Java in all programming languages function returns ONLY one value.
//from one functions returning 2 values
#include<iostream.h>
#include<conio.h>
int fun(int &x,int a,int b)
{
cout<<x<<" "<<&x<<endl;
x=a+b;
return a;
}
void main()
{
clrscr();
int fun(int &x,int a,int b);
int y=10;
cout<<fun(y,1,2)<<endl;
cout<<y<<" "<<&y<<endl;
getch();
}
//It returns values by reference,
//It's modifying another value. But there's return a;