answersLogoWhite

0


Best Answer

The main difference is that return values can be used in compound statements (such as assignments), whereas output parameters cannot. An output parameter is a non-const parameter that is passed by reference or as a pointer variable.

As a general rule, every function should return something through the return value, even if only an error level where zero would typically indicate success (but not always). A function that does not return anything (returns void) is not strictly a function, it is better described as a procedure. However, if a function can be guaranteed never to fail (provides trivial functionality) and has no need to return any other value to the caller, then returning void is a logical option. Just because a function should return a value doesn't mean that it must return a value.

However, the return value is limited by the fact that it only permits one value to be returned by a function. Output parameters allow a function to return several values at once and can be used in conjunction with the return value. If there is no need for the return value, it should be used to indicate the error level of the function wherever it would be appropriate. However it is not unusual for a function to accept a reference as an output parameter and to also return that same reference via the return value.

Note that although you could return multiple values via a struct or class type, this should only be considered if you have several functions that can make use of the struct or class type. However, in most cases it would be simpler to make those functions members of the struct or class itself.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between using a return value and a pass-by-reference parameter?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can you have in-out parameter in a function if not then why?

because function have return sts thatway it is not necessary out parameter to function


Why void is used in c language?

void as function return-type means no return value void as function parameter means no parameter void * as pointer type means generic pointer


What do parameters and return values have to do with methods?

Parameters and return values are a major part of methods. When defining a method, you must include information about the data types of the return value and the parameters. An example of a method definition is this: public int getSumOfNumbers( int number1, int number2, int number3 ) { return ( number1 + number2 + number3 ); } The word "int" right after the word "public" is the return type. It describes what data type will be returned by the method. In this case, it was int, or integer. The sequence of words in between the parantheses, "int number1, int number2, int number3", is the parameter list. Each of the phrases separated by a comma in the parameter list is a parameter. The first word - in this case "int" - is the data type of the parameter. It describes what type of variable the parameter will be. The second word - "number1", "number2", or "number3" - is the name of the parameter. Every parameter must have a data type and a name, and every method must have a return type: even a method that returns nothing. For example: public void evaluateNumber(int number) { if ( number > 0 ) { System.out.println( number + " is positive." ); } else if ( number < 0 ) { System.out.println( number + " is negative." ); } else { System.out.println( number + " is zero." ); } } When a method does not return data, its return type must be defined as void, as it is above.


What should the air temp difference be between the supply and return side of a 4 ton 16 seer unit?

20 degree difference


D Write a function that returns 2n where n is an input parameter?

int 2n(int n){return n << 1;)

Related questions

Javascript function for the difference between 2 numbers?

This function will accept two parameters and return the difference between the first and second parameter. function diffBetween ( a, b ) { return a-b; } //end diffBetween


What does missing return url parameter mean?

missing return URL=UMBRELLA RAPE LICK parameter


What is the difference between the sales return and purchase return?

hhhh


What is a parameter in C?

Int x=0; //which have zero value call trival return x=3; // we call as parameter


What is parameter in c?

Int x=0; //which have zero value call trival return x=3; // we call as parameter


What is the difference between law of return to variable proportion and law or return to scale?

There is a big difference between both the laws.The basi difference between them is that i dont know 1st but i know the 2nd one


What is operation signature in UML?

Syntax for UML operation is: operation ::= [ visibility ] signature [ oper-properties ] Signature of the operation has optional parameter list and return specification. signature ::= name '(' [ parameter-list ] ')' [ return-spec ] Name is the name of the operation. Parameter-list is a list of parameters of the operation in the following format: parameter-list ::= parameter [ ',' parameter ]* parameter ::= [ direction ] parm-name ':' type-expression [ '[' multiplicity ']' ] [ '=' default ] [ parm-properties ] See details and examples in the provided link.


Can you have in-out parameter in a function if not then why?

because function have return sts thatway it is not necessary out parameter to function


Why void is used in c language?

void as function return-type means no return value void as function parameter means no parameter void * as pointer type means generic pointer


What is the difference between return on investment and return on assets?

They are one and the same and they are used interchangeably.


Difference between returns to scale and constant return to scale?

differentiate between returns to scale and constant return to scale


What is the difference between a warranty and insurance?

the difference between a warranty and insurance, is a warranty is when you can return it to either get another or to just return it. insurance is when you have coverage over the object or living being.