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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
Can u return two values using return keyword? If yes, how?
If no, why?
 Question Submitted By :: Sivavendra
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 1
no. because return keyword return only one value.that ia 0 
or 1.
 
Is This Answer Correct ?    8 Yes 3 No
C.saranya
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 2
in c a function can only written one value 
the return value could be of any data type
 
Is This Answer Correct ?    7 Yes 2 No
Abhijit Roy
 
 
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 3
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 7 No
Vignesh1988i
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 4
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 ?    6 Yes 5 No
Vignesh1988i
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 5
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 ?    7 Yes 2 No
Pancuz
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 6
no.
 
Is This Answer Correct ?    1 Yes 1 No
Vaibhav
 
  Re: Can u return two values using return keyword? If yes, how? If no, why?
Answer
# 7
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 ?    1 Yes 0 No
Vikas Shakya
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }  2
f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output? Hughes6
which operator having highest precedence? a.)+ b.)++ c.)= d.)%  3
two progs are given. one starts counting frm 0 to MAX and the other stars frm MAX to 0. which one executes fast. Verifone5
without using arithmatic operator convert an intger variable x into x+1  1
C program to perform stack operation using singly linked list  3
c program to add and delete an element from circular queue using array  1
True or false: If you continuously increment a variable, it will become negative? 1) True 2) False 3) It depends on the variable type  5
What is the difference between typeof(foo) and myFoo.GetType()?  1
how to implement stack operation using singly linked list  1
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?  1
what is mallloc()?how it works? Excel3
How do you write a program which produces its own source code as its output?  3
what is the difference between declaration ,defenetion and initialization of a variable? LG-Soft5
what are brk, sbrk? Oracle1
ABCDCBA ABC CBA AB BA A A  1
c programming of binary addition of two binary numbers  1
main() { printf(5+"Vidyarthi Computers"); }  6
how to convert binary to decimal and decimal to binary in C lanaguage  4
print the following using nested for loop. 5 4 3 2 1 1 2 3 4 3 2 1 1 2 1 2 1 1 2 3 4 3 2 1 1 2 3 4 5  5
 
For more C 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