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
What is spaghetti programming?
The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?
What is the difference between union and anonymous union?
explain what are actual arguments?
Explain what are global variables and explain how do you declare them?
What is header file in c?
p*=(++q)++*--p when p=q=1 while(q<=6)
When can you use a pointer with a function?
What are structure members?
What are structures and unions? State differencves between them.
What is ambagious result in C? explain with an example.
What is double pointer in c?
What is the scope of local variable in c?
What is the use of a conditional inclusion statement in C?
What are derived data types in c?