answersLogoWhite

0


Best Answer

return var_name;

e.g

int fun()

{

int x=...;

return x;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which Keyword is used to return some value from a function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

CAN Overloaded functions can return default values?

I'm not sure I understand you as it wouldn't make sense for a function to return a default value. Do you actually mean can a function return an argument that has a default value? If so, then yes. Any argument passed to a function, whether defaulted or not, can be returned by the same function. If the argument is passed by value then you must return it by value. If passed by reference (which cannot be defaulted) then you can either return by reference or by value. However, if you pass by non-constant reference then you can just use the reference as an output argument, and use the actual return value for some other purpose, such as reporting any error condition(s) created by the function. Overloaded functions are no different to ordinary functions, the only criteria is that each overload has an unique signature. The return value does not form any part of the signature, thus signatures cannot differ by return type alone.


Is main a keyword?

No. Main is not a keyword in C or C++. However, your program, when linked, must provide one and only one externally scoped entry point to main(). If you use main in some other context, and you do not provide one and only one entry point main(), then your program will not link nor run.


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.


Can return statement be in a void method in java?

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.


What are the advantages of pass by reference as compared to pass by value?

Call by reference, particularly when applied to objects, because call by value automatically invokes an object's copy constructor, which is seldom desirable when passing objects into functions.

Related questions

CAN Overloaded functions can return default values?

I'm not sure I understand you as it wouldn't make sense for a function to return a default value. Do you actually mean can a function return an argument that has a default value? If so, then yes. Any argument passed to a function, whether defaulted or not, can be returned by the same function. If the argument is passed by value then you must return it by value. If passed by reference (which cannot be defaulted) then you can either return by reference or by value. However, if you pass by non-constant reference then you can just use the reference as an output argument, and use the actual return value for some other purpose, such as reporting any error condition(s) created by the function. Overloaded functions are no different to ordinary functions, the only criteria is that each overload has an unique signature. The return value does not form any part of the signature, thus signatures cannot differ by return type alone.


Is main a keyword?

No. Main is not a keyword in C or C++. However, your program, when linked, must provide one and only one externally scoped entry point to main(). If you use main in some other context, and you do not provide one and only one entry point main(), then your program will not link nor run.


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 the advantages of call by reference?

Whenever you pass a value to a function, that value must be copied. If the value is large or complex, this can hinder performance, particularly when the function does not need to alter the value. To improve performance, we use the pass by reference semantic. Rather than passing the value itself, we pass the address of the value. That is, the address is copied, not the value. The function can then refer to the value by dereferencing the address. Ideally, pass by reference should only be used when the function does not need to alter the value. This is achieved by declaring the function's formal argument a pointer to constant type. This makes it clear to the caller the value of the actual argument will not be altered by the function. In some cases, we do require the function to alter the value. In these cases the argument is regarded as being an output parameter because it allows the function to return another value besides the return value. Typically, the caller will allocate some memory for the function to use (perhaps initialising it with a value), and then pass the address of that memory to the function. The function's formal argument is therefore declared a pointer to non-constant type, making it clear to the caller that the function will modify the value being pointed.


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.


Can return statement be in a void method in java?

the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.


What is the difference between procedures and functions?

Procedures are a set of instructions that perform a specific task but do not return a value, while functions are similar but return a value after completing their task. Functions are typically used when you need to perform some computation and return a result, while procedures are used for tasks that don't require a return value.


What is eigenfunction?

when an operator operate on a function and same function is reproduced with some numerical value then the function is called eigenfunction and the numerical value is called eigen value.


What are limits in maths?

Limits (or limiting values) are values that a function may approach (but not actually reach) as the argument of the function approaches some given value. The function is usually not defined for that particular value of the argument.


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 are the advantages of pass by reference as compared to pass by value?

Call by reference, particularly when applied to objects, because call by value automatically invokes an object's copy constructor, which is seldom desirable when passing objects into functions.


What is the main function of C?

The main function is the entry point for the application. Each program written in C or C++ will start at the first line in the main function, and cease execution once the main function returns control to the operating system (either via a return keyword in the main function, an exit(3) function call, or by "running off" the end of the main function). A program will not compile if it is missing the main function. Some variants of C++ have an alternate entry point (including those written for Microsoft Windows).