+ 3

What is the meaning of "a function which does not return a value" and " a function returns some value" ?? Please send the answer

28th Jul 2017, 10:20 AM
Yasir Faiz Ahmed
Yasir Faiz Ahmed - avatar
7 odpowiedzi
+ 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
28th Jul 2017, 10:45 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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; }
28th Jul 2017, 10:43 AM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 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; }
28th Jul 2017, 11:54 AM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 1
what is return? what it means?
28th Jul 2017, 11:21 AM
Yasir Faiz Ahmed
Yasir Faiz Ahmed - avatar
0
In Python 3 is for this case a special codeword : pass. Here is a example : def some_func() : pass
28th Jul 2017, 11:26 AM
lux arcadia
lux arcadia - avatar
0
It defines a valid function that returns nothing. You can use instead pass, none, but pass is more elegant.
28th Jul 2017, 11:28 AM
lux arcadia
lux arcadia - avatar
0
Sorry for spaming about python.
28th Jul 2017, 11:30 AM
lux arcadia
lux arcadia - avatar