C Programming - Functions - Discussion
Discussion Forum : Functions - True / False Questions (Q.No. 2)
2.
Functions cannot return more than one value at a time
Answer: Option
Explanation:
True, A function cannot return more than one value at a time. because after returning a value the control is given back to calling function.
Discussion:
10 comments Page 1 of 1.
Nitish said:
1 decade ago
But if we use call by reference method in which original values are passed then a function can return more than 1 value at a time.
e.g.
#include<stdio.h>
void areaperi(int,float *,float *);
void main()
{
int radius;
float area,perimeter;
printf("\nEnter radius of a circle");
scanf("%d",&radius);
areaperi(radius,&area,&perimeter);
printf("\n Area=%f \n Perimeter=%f,area,perimeter");
}
void areaperi(int r, float *a, float *p)
{
*a=3.14*r*r;
*p=2*3.14*r;
}
e.g.
#include<stdio.h>
void areaperi(int,float *,float *);
void main()
{
int radius;
float area,perimeter;
printf("\nEnter radius of a circle");
scanf("%d",&radius);
areaperi(radius,&area,&perimeter);
printf("\n Area=%f \n Perimeter=%f,area,perimeter");
}
void areaperi(int r, float *a, float *p)
{
*a=3.14*r*r;
*p=2*3.14*r;
}
Sagar said:
1 decade ago
Yup @Nitish, you are right. That's what I wanna say. A function can return multiple values by using call by reference. A mixed call containing call by value and call by reference can do it also.
Santhosh said:
1 decade ago
Then what is the answer? They didn't update it.
Nandyvijay said:
9 years ago
Can anyone give the correct explanation for this?
Akshat said:
9 years ago
It can only return 1 value. We are not directly getting two values by using call by reference, we have nowhere used return statement two times. Therefore function can only return 1 value.
Harika said:
9 years ago
Usually function returns only one value, but using structures we can return more than one value.
Vinay said:
8 years ago
We can also return multiple values at the time of return.
Such as return(2,3);
Such as return(2,3);
Anita said:
8 years ago
According to me, it is possible to return more than one value in a function by making use of pointers.
Saumya said:
8 years ago
Yes, Function can return more than one values at a time. We can do this using pointer. Like *Sum = a;.
Kranthi said:
5 years ago
@Vinay.
It returns 3 only.
if k=return(2,3)
we will get k=3 only.
It returns 3 only.
if k=return(2,3)
we will get k=3 only.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers