Can u return two values using return keyword? If yes, how?
If no, why?
Answer Posted / vignesh1988i
ya we can return two or more than two values..... it's
possible..
by using concept of POINTERS..... but no need of return
keyword at all.....
instead of call by value in the function use call by
reference concept....
take the following program:
int fun(int *,int *);
void main()
{
int j=800,k=1000;
fun(&j,&k);
printf("%d",j,k);
getch();
}
int fun(int *q,int *w)
{
q=q/2;
w=w/2;
}
the output of the followiung is : 400 & 500.
how it's possible, i ll explain,
since we are calling by reference we
are sending the address of the two variables. so in fun.
definition we are catching it by pointers..... so that
pointer variable is holding the address of the two variables
in main fun. which is passed through address.... so in the
function we are changing the values of j & k.... so this
will change the value directly in the address of those two
variables j & k....... so implicitely two values are
returned wit out return keyword....
| Is This Answer Correct ? | 7 Yes | 9 No |
Post New Answer View All Answers
shorting algorithmS
Explain what are the different data types in c?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
Is fortran faster than c?
What is union in c?
What is hashing in c language?
What does it mean when a pointer is used in an if statement?
Explain the properties of union. What is the size of a union variable
What is the modulus operator?
What are extern variables in c?
Define and explain about ! Operator?
Is int a keyword in c?
Can a pointer point to null?
Is void a keyword in c?
The statement, int(*x[]) () what does in indicate?