answersLogoWhite

0


Best Answer

Consider this example:

#include

int add(int x, int y)

{ int n=x+y;

return n; }

int main()

{ Using namespace std;

cin >> x;

cin >> y;

cout << add(x,y);

return 0; }

What happens is the main() function asks the user for 2 integers then sends them to add() in the cout statement. Add() adds the two integers and returns the sum to the function that called it (main()) so technically 'add(x,y)' in the cout statement is replaced with add()'s return value. So if the user said x=1 and y=2, the program would print 3. NOTE:

For example, return 0 in main(). Anything else is an error code that is RETURNED TO THE OS or SHELL.

In the of Unix/Linux, we can see the returned value of main using

echo $?

In the case of Windows, we can see the returned value of main using

echo %ERROR_LEVEL%

while we are in DOS or Command prompt

User Avatar

Wiki User

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

Wiki User

13y ago

It's up to you to decide if you want your function to return a value or not; in the latter case define it as 'void', eg:

void exit (int exit_code);

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

It make you feel happier.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is meant by a function returning a value in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Call by function in c language?

I guess you meant the following:'In C language, when you call a function,the parameters are passed by-value.'


How do you rectify the waring is function should return a value in turbo c plus plus?

By returning a value. Or using type 'void'.


Why return 1 is used in int main function in c?

Returning a value of 1 (or any value besides zero) from main indicates an error.


In C plus plus when a function is executing what happens when the end of the function is reached?

Control is returning to the caller of the function.


How do you use return?

In C/C++ programming and most other procedural languages, you use a return statement to return control to the calling function. In the case of the global main function, a returnstatement terminates the program, releasing all memory used by the program and returning control to the execution environment.Functions that return void do not return a value and therefore do not require a return statement, unless the function needs to return early (before falling off the end of the function). Functions that return values must use a returnstatement to return the appropriate value to the caller.In C++ (but not in C), the global main function does not require a return statement unless returning early. When omitted, the global main function implicitly returns the value 0 (to the execution environment) when execution falls off the end of the function. To return any other value, a return statement is required.


Which purpose you want to use return statement in c?

Surprise, surprise: returning from a function.


How do you invoke function result () takes two float argument and returns an integer in c plus plus program?

You can do this by creating a forwarddeclaration of the function. You can call the forward drclared function inside the main to use it.int result(float num1, float num2);intmain(void){int value = result(3.14, 2.74);return (0);}intresult(float num1, float num2){int value = 0;// function codes goes here// you can alter the value of variable 'value'return (value);}The returning value of the 'result()' function is assigned to variable 'value' in 'main()'.


How does the compiler differentiate the statement and function in C programming?

statement should not return a value but function returns a value


What is meant by arguments in c?

Arguments appear in functions and in function calls. Arguments passed to a function are known as actual arguments. The arguments used by the function are known as the formal arguments. In C, all arguments are passed by value, such that the formal argument is a copy of the actual argument.


What is default value of formal arguments?

In C, there is no default value for formal parameters. In C++, there can be, but the value is whatever you declare in the function declaration.


What is meant by function declaration in C language?

The name of the function is established by what is called function declaration. It also establishes the number and the types of parameters.


What is the function of a director?

c. to determine whether a request is meant for the client CPU or the server.