Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Are the variables argc and argv are always local to main?

0 Answers  


What is the difference between struct and typedef struct in c?

0 Answers  


what is the value of b if a=5; b=++a + ++a

31 Answers   Infosys, TCS, Tech Mahindra,


Explain what is the benefit of using enum to declare a constant?

0 Answers  


What are near, far and huge pointers?

0 Answers   Hexaware, Thomson Reuters, Virtusa,


1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.

4 Answers  


print out of string in this format; 1. "rajesh" 2. \n 3. %d

5 Answers   mpower,


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

0 Answers   Aspire, Infogain,


Write a programme to find even numbers without using any conditional statement?

3 Answers   ADD Software, Infosys,


Are comments included during the compilation stage and placed in the EXE file as well?

0 Answers  


What is static memory allocation? Explain

0 Answers  


What is the 'named constructor idiom'?

0 Answers  


Categories