ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How to return multiple values from a function?
 Question Submitted By :: Solidcube
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to return multiple values from a function?
Answer
# 1
Make array of values and return the array address as long. 
Now using pointer traverse through the value.
 
Is This Answer Correct ?    7 Yes 1 No
R. Kumaran
 
  Re: How to return multiple values from a function?
Answer
# 2
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 ?    8 Yes 12 No
Splurgeop
 
 
 
  Re: How to return multiple values from a function?
Answer
# 3
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 ?    4 Yes 5 No
Prasanta Maiti
 
  Re: How to return multiple values from a function?
Answer
# 4
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 ?    4 Yes 4 No
Shruti
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
#define int char main() { int i=65; printf("sizeof(i)=%d",sizeof(i)); }  1
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
Write a routine that prints out a 2-D array in spiral order Microsoft2
main() { int i = 3; for (;i++=0;) printf(“%d”,i); }  1
const int perplexed = 2; #define perplexed 3 main() { #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed); } a. 0 b. 2 c. 4 d. none of the above HCL1
how to return a multiple value from a function? Wipro2
int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p  1
main() { extern int i; i=20; printf("%d",sizeof(i)); }  1
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }  1
int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }  1
main() { if ((1||0) && (0||1)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above HCL1
main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }  1
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }  1
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }  1
main() { char not; not=!2; printf("%d",not); }  1
main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }  1
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }  1
How do you write a program which produces its own source code as its output?  7
main() { printf("%d", out); } int out=100;  1
main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } } a. 5, 4, 3, 2, 1 b. 0, 1, 2, 3, 4 c. 0, 1, 2, 4, 8 d. 1, 2, 4, 8, 16 HCL1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com