+ 3
What is the meaning of "a function which does not return a value" and " a function returns some value" ?? Please send the answer
7 Answers
+ 8
// void function, no return value
void function()
{
//do something
}
// int function, return int value
int function ()
{
//do something
return 1;
}
// char function, return char value
{
// do something
return 'a';
}
// etc
+ 2
You can see that functions that return nothing start with void keyword and have no return statement in their body.
// a function returning no value
void return_nothing() {
cout << "I have nothing to return";
}
Functions that return something start with the datatype of the thing you return, like int, double, string, etc.
// a function returning some value
int sum(int a, int b) {
// return sum of a and b
return a + b;
}
+ 2
@Yasir Faiz Ahmed, when you call a function to do something, after it's done it can return some value
So return specifies what the function returns
example of a return function in C++:
#include <iostream>
using namespace std;
// user defined function returning a squared number
int square(int number) {
return number * number;
}
int main() {
int number = 4;
// print number
cout << number << endl;
// print squared number
cout << square(number) << endl;
// always have "return 0;" at the end of main function
return 0;
}
+ 1
what is return? what it means?
0
In Python 3 is for this case a special codeword : pass. Here is a example : def some_func() : pass
0
It defines a valid function that returns nothing. You can use instead pass, none, but pass is more elegant.
0
Sorry for spaming about python.