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


Please Help Members By Posting Answers For Below Questions

What is spaghetti programming?

872


The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

1000


What is the difference between union and anonymous union?

1037


explain what are actual arguments?

823


Explain what are global variables and explain how do you declare them?

832


What is header file in c?

825


p*=(++q)++*--p when p=q=1 while(q<=6)

1470


When can you use a pointer with a function?

742


What are structure members?

814


What are structures and unions? State differencves between them.

842


What is ambagious result in C? explain with an example.

2294


What is double pointer in c?

762


What is the scope of local variable in c?

770


What is the use of a conditional inclusion statement in C?

824


What are derived data types in c?

793