C Programming - Functions - Discussion

2. 

Functions cannot return more than one value at a time

[A]. True
[B]. False

Answer: Option A

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.


Nitish said: (Sep 5, 2010)  
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;
}

Sagar said: (Oct 13, 2013)  
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: (Jul 7, 2015)  
Then what is the answer? They didn't update it.

Nandyvijay said: (Jul 21, 2016)  
Can anyone give the correct explanation for this?

Akshat said: (Sep 12, 2016)  
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: (Oct 10, 2016)  
Usually function returns only one value, but using structures we can return more than one value.

Vinay said: (Jul 23, 2017)  
We can also return multiple values at the time of return.
Such as return(2,3);

Anita said: (Aug 30, 2017)  
According to me, it is possible to return more than one value in a function by making use of pointers.

Saumya said: (Sep 12, 2017)  
Yes, Function can return more than one values at a time. We can do this using pointer. Like *Sum = a;.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.