answersLogoWhite

0


Best Answer


Strictly speaking, only one.

However, a trick many programmers use is to have the function create "side effects" by changing the value of its arguments as well as returning a value. A pseudocode example might be something like a file-existence checker. It would be a boolean function that returns TRUE if the file exists and FALSE if it doesn't. However, depending on the language used it could also modify its arguments so they provided the file's size and record type if it exists. For example: if bFileExists (cFileName, iFileSize, iRecType) then {do something with iFileSize ...}


User Avatar

Wiki User

17y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

You can declare a function to accept an arbitrary number of arguments:

int howManyParameters(int parameterCount, ...)

{

va_list ap;

va_start(ap, parameterCount);

printf("Function called with %d parameters:\n", parameterCount);

for(int i = 0; i < parameterCount; i++)

printf(" %d", va_arg(ap, int));

printf('\n');

return n;

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

You can not return multiple values from a function. A function is a routine that takes zero or more arguments and returns no or one value. You could pass one of the arguments by reference (pointer) instead of by value, and alter that object in the caller's address space. This may or may not be desired, based on your criteria for side effects and/or purity. You could also return a class containing more than one value, but at the function interface you are still returning only one value.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A user defined function can "return" a maximum of one value and a minimum of zero value to any caller function. But, by using call by reference, returning multiple values can be simulated, though, no "returning" actually happens.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

you cannot return more than one values, instead you have to pass address of a variable to the function, then the function can modify values stores in those address locations.

e.g

#include<stdio.h>

main()

{

int a=5,b=10;

printf("a= %d b=%d \n",a,b);

fun(&a,&b);

printf("a= %d b=%d",a,b);

}

void fun(int *x,int *y)

{

int t=*x;

*x=*y;

*y=t;

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

One. Output parameters can be used to return additional values. You can also return struct or class types to return more than one value via a single value.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

One. Of course parameters can be pointers, so value can be passed back with them, for an example see scanf.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Zero or one.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

No

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can function return more than one value?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is it possible for a function to return more than one value at a time?

No, you can only return one value with a return statement. However, you can return a structure or pointer, so the real answer is yes, though requiring some added complexity.


What is return in programming?

The return statement is used in functions to return control to the caller. If the function is declared non-void, the return statement also allows the programmer to return a value to the caller.


Can a function have more than two return statement?

Yes, there is no limit.


What is mean void in c plus plus?

Void means there is no data type. So if you have a void function it does not return a value (and attempting to do so will cause an error) whereas a non-void function (ex. int, long, String, bool, etc) will return a value of that type.


What is Parameter Passing and Returning values.. in Programming.. preferbly Visual Basic?

Parameters are the variables you pass to functions. Return values are the variables that are returned by those functions. Values can also be returned by the parameters themselves (such parameters are said to be output parameters).The variables you pass and return from functions will either be by value or by reference. Only references can be output parameters, since passing by value creates an automatic copy of the value which falls from scope when the function returns. Pointer variables are always passed by value. To pass a reference to a pointer you must pass a pointer to the pointer, which is itself passed by value, but refers to the pointer.Constant references are the preferred method of passing variables to functions, since there is no need to copy the variable you pass and because it is constant, the original value is left unaltered. Non-constant reference is the next best method, but only if you expect changes to be reflected back in your value (an output parameter). If you do not expect changes, then you must pass by value or, when that isn't an option, create a copy of your value and pass by non-constant reference. The only difference is that passing by value automatically destroys the copy when the function returns.Ignoring output parameters, a function can only return, at most, one value. A function that returns void has no return value, however it is good practice to always return something, even if only an integer to indicate whether the function was successful (zero) or not (non-zero). If the function is a logical function, such as Add( X, Y ), or an accessor, such as GetName() then it makes more sense to return the actual result of the function via the return value. If you need more than one return value, then you must use output parameters, passed by reference, which allows the return value to be used as an error indicator.Generally you will want to store the return value of a function, especially if the return value is a memory allocation. If you don't store the return value, the value is lost forever, unless you re-call the function with the same parameters, which is highly inefficient. However, if you only need to know the result of a function once, you don't need to store it, so long as you act upon it immediately, usually as part of a conditional expression. E.g.,int x, y; // Uninitialised, values unknown.if( x + y == 12 ) // call the int::operator+ function.// x+y is definitely 12.else// x+y is definitely not 12, but the actual sum is no longer known at this point.

Related questions

Why a return function does not return more than one value?

It's by design.


What is the use of pointer?

To point with. 1. To manipulate parts of an array. 2. To return more than value from a function.


Is it possible for a function to return more than one value at a time?

No, you can only return one value with a return statement. However, you can return a structure or pointer, so the real answer is yes, though requiring some added complexity.


What is return in programming?

The return statement is used in functions to return control to the caller. If the function is declared non-void, the return statement also allows the programmer to return a value to the caller.


Can a function have more than two return statement?

Yes, there is no limit.


Is the graph of every line a function?

No. One argument of function may have only one value. So, if it has more than one value, it is not a function.


What is the need for return statements in c?

It's not so much a need but a requirement. Every C function must contain at least one return statement, typically at the end of the function body (before the closing brace). However, a C function may have more than one return path, and each requires its own return statement. Note that it does not matter whether the function returns a value or not; even a function that returns void must have a return statement. In C++ the rules regarding return statements are more relaxed. Functions that return void do not require a return statement at all; when execution reaches the closing brace of a void function, a return statement is implied. All functions that return a value of any type other than void must have a return statement. The one exception to this rule is the global main function which must always return an int. If the global main function has no return statement then the value 0 is implicitly returned to the calling environment (the value 0 is typically used to indicate no error). However, if we need to return other values (including 0), then we must include a return statement. Functions that have multiple return paths are considered poor style and should be avoided. Functions are generally much easier to read and maintain when there is only one return path which should logically terminate at the very end of the function. However, eliminating multiple return paths can also produce more efficient machine code, particularly in functions with highly complex return paths. Eliminating multiple return paths needn't be difficult, we simply need to refactor the function such that each unique return path is representing by some function which returns the appropriate value. The calling function simply stores that value and returns it at the end of the function, thus simplifying the overall complexity of the calling function. Refactoring complex functions into smaller, simpler function calls is good style in and of itself; well-named, descriptive function calls result in code that is largely self-documenting and thus more abstract. Although function calls are themselves expensive, small and simple functions can be easily inline-expanded by the compiler's optimisers, so it's a win-win.


How do you identify if the given equation is function or not?

A function is an equation (a relation) which has only one y-value for every x-value. If a single x-value has more than one y-value, the equation is no longer called a function.


What is mean void in c plus plus?

Void means there is no data type. So if you have a void function it does not return a value (and attempting to do so will cause an error) whereas a non-void function (ex. int, long, String, bool, etc) will return a value of that type.


What is heaviside function?

The Heaviside function is a discontinuous step function. It is 0 for all values less than some specific value. At and after that value, it takes the value 1. The Heaviside function can be used to represent an "Off-On" function.See link for more.The Heaviside function is a discontinuous step function. It is 0 for all values less than some specific value. At and after that value, it takes the value 1. The Heaviside function can be used to represent an "Off-On" function.See link for more.The Heaviside function is a discontinuous step function. It is 0 for all values less than some specific value. At and after that value, it takes the value 1. The Heaviside function can be used to represent an "Off-On" function.See link for more.The Heaviside function is a discontinuous step function. It is 0 for all values less than some specific value. At and after that value, it takes the value 1. The Heaviside function can be used to represent an "Off-On" function.See link for more.


What is a relation that assigns exactly one value in the range to each value in the domain?

one value for "Y" for every "X" is related by a function... it cannot be a function if it has more than one Y value for an X value


What is the relation that assigns exactly one value in the range to each value in the domain?

one value for "Y" for every "X" is related by a function... it cannot be a function if it has more than one Y value for an X value