Can u return two values using return keyword? If yes, how?
If no, why?

Answers were Sorted based on User's Feedback



Can u return two values using return keyword? If yes, how? If no, why?..

Answer / c.saranya

no. because return keyword return only one value.that ia 0
or 1.

Is This Answer Correct ?    15 Yes 4 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / pancuz

yes we can return two or more values from a function using
return keyword...

Use structure...return type of the function will b 'struct'
and v ll store value in struct type.

Is This Answer Correct ?    10 Yes 2 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / abhijit roy

in c a function can only written one value
the return value could be of any data type

Is This Answer Correct ?    10 Yes 4 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / vignesh1988i

sorryt sorry i made a mistake... i

in the line q=q/2 is wrong
correct as *q=*q/2;
and *w=*w/2;

since addresses cant be divided...

very sorry

Is This Answer Correct ?    9 Yes 6 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / vaibhav

no.

Is This Answer Correct ?    2 Yes 2 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / vikas shakya

Using the return statement u can only return one value at a
time.
So you can either return the value of a variable like you
can return an integer, or you can return pointer (which may
contain more than one values), which is pointing to
dynamically allocated location, Like in given below example:
//Returning two values from a function.

#include "stdio.h"
#include "malloc.h"

int *values()
{
int *ptr;
ptr = (int*)malloc(2);
*ptr = 10;
*(ptr+1) = 20;
return ptr;
}

int main()
{
int *ptr = values();
printf("%d\n%d",*ptr,*(ptr+1));
return 0;
}

Is This Answer Correct ?    2 Yes 3 No

Can u return two values using return keyword? If yes, how? If no, why?..

Answer / 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

More C Interview Questions

c program for searching a student details among 10 student details

0 Answers  


How to write a code for reverse of string without using string functions?

0 Answers   TCS,


I came across some code that puts a (void) cast before each call to printf. Why?

0 Answers  


what is meant by flushll() in c programming?

1 Answers  


Why main is not a keyword in c?

0 Answers  






What is the use of #define preprocessor in c?

0 Answers  


How do you define a string?

0 Answers  


Efficient data structure for store/search list of 1000 records a)array b)double linked list c)circular queue d)hash table

3 Answers   Value Labs,


find the output of the following program main() { int x=5, *p; p=&x; printf("%d",++*p); }

10 Answers   Amdocs, TCS,


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

0 Answers  


How do you use a 'Local Block'?

0 Answers   Ericsson,


Write a program in c to replace any vowel in a string with z?

0 Answers   IBS,


Categories