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
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
How can I write a function analogous to scanf?
what is the function of pragma directive in c?
What are variables and it what way is it different from constants?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
Can you pass an entire structure to functions?
What extern c means?
When would you use a pointer to a function?
What is the use of pointers in C?
Explain how do you list a file’s date and time?
What is static memory allocation?
Why is it usually a bad idea to use gets()? Suggest a workaround.
Explain how can type-insensitive macros be created?
Can you write the algorithm for Queue?
how to write a c program to print list of fruits in alpabetical order?