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 type is sizeof?
Differentiate between full, complete & perfect binary trees.
Explain how can I right-justify a string?
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
Explain continue keyword in c
If errno contains a nonzero number, is there an error?
Explain how do you generate random numbers in c?
Explain how are portions of a program disabled in demo versions?
How can I list all of the predefined identifiers?
What is string function c?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
Define circular linked list.
Here is a good puzzle: how do you write a program which produces its own source code as output?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
What is use of pointer?