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...


How to return multiple values from a function?

Answers were Sorted based on User's Feedback



How to return multiple values from a function? ..

Answer / r. kumaran

Make array of values and return the array address as long.
Now using pointer traverse through the value.

Is This Answer Correct ?    61 Yes 19 No

How to return multiple values from a function? ..

Answer / prasanta maiti

Make array of values and return the array address as long.
simple example:
void main()
{
int a[10],i,n;
int *new_value_array;
printf("\n Enter how many number you want to enter? ");
scanf("%d",&n);
for(i=0;i<n;i++)
sacnf("%d",&a[i]);
printf("\n old value of the array is:");
for(i=0;i<n;i++)
printf("\t%d",a[i]);
new_value_array = array_modify(a,n);
printf("\n new value of the array is: \n");
for(i=0;i<n;i++)
printf("\t%d",*(new_value_array+i));
getch();
}
int *array_modify(int a[10],int n)
{
int i;
for(i=0;i<n;i++)
a[i]=a[i]*4;
return(a);
}

Is This Answer Correct ?    45 Yes 14 No

How to return multiple values from a function? ..

Answer / shruti

Multiple values can be returned from a function,
using the call by refrance method.

in this method, we pass pointers as the argument to the
funtion..

Is This Answer Correct ?    38 Yes 15 No

How to return multiple values from a function? ..

Answer / saurabh

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct
{
int a;
int b;
}Mystruct;

Mystruct myfun();

int main()
{
Mystruct ms2;
ms2 = myfun();
printf("val1: %d val2: %d",ms2.a,ms2.b);
return 0;
}

Mystruct myfun()
{
int a,b;
Mystruct ms;

a = 10;
b = 20;
ms.a=a;
ms.b=b;

return(ms);
}

Is This Answer Correct ?    14 Yes 15 No

How to return multiple values from a function? ..

Answer / manjunath sudnye

Just Make Array Of Pointer For Any Data Type And Return The
Base Address Of Thgat Pointer.
e.g
int *Ptr[5]={1,2,3,4,5};
//now see you can use 5 pointers for manupulation the
valuesand can return it by.
return Ptr;

Is This Answer Correct ?    2 Yes 5 No

How to return multiple values from a function? ..

Answer / j.nithya

we can return multiple values from a function by using pointer.... Just store your multiple values which you want to return and return the base address......Store the values in the array and return the base address of the array.

Is This Answer Correct ?    3 Yes 10 No

How to return multiple values from a function? ..

Answer / splurgeop

you can return multiple values from the function by using
mechanism called "call-by-reference".
for example:

void main()
{
int area,*circumference;
area=function(area,circumference);
cout<<"the area is "<<area;
cout<<"the circumference is"<<circumference;
}
int function(int a,int *b)
{
a=12;
int temp=a*3;
b=&temp;
return a;
}

// this is just an example............


// you can also use array and return the adress of the
array in the main and can use to traverse the entire array
and return multiple values from function.

Is This Answer Correct ?    34 Yes 60 No

Post New Answer

More C Code Interview Questions

Find the largest number in a binary tree

7 Answers   Infosys,


Write a C program to add two numbers before the main function is called.

11 Answers   Infotech, TC,


What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }

1 Answers  


Who could write how to find a prime number in dynamic array?

1 Answers  


write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

2 Answers  


Which version do you prefer of the following two, 1) printf(ā€œ%sā€,str); // or the more curt one 2) printf(str);

1 Answers  


why java is platform independent?

13 Answers   Wipro,


main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }

2 Answers  


Write a function to find the depth of a binary tree.

13 Answers   Adobe, Amazon, EFI, Imagination Technologies,


#include<stdio.h> int main() { int x=2,y; y=++x*x++*++x; printf("%d",y); } Output for this program is 64. can you explain how this output is come??

1 Answers  


main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }

1 Answers  


void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā€œ%dā€, i); }

2 Answers  


Categories