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   To Refer this Site to Your Friends   Click Here
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 ?    9 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 ?    9 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
 
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4 HCL1
main() { clrscr(); } clrscr();  1
program to find the roots of a quadratic equation HP3
main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4 HCL1
main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256 HCL1
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
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped IBM1
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }  1
main() { if (!(1&&0)) { 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() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }  1
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }  1
main() { int c=- -2; printf("c=%d",c); }  1
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }  1
Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution) Microsoft5
How to reverse a String without using C functions ? Wipro14
How to read a directory in a C program?  4
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD Synergy6
Write a program that find and print how many odd numbers in a binary tree  1
#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?  2
#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }  1
 
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