How many values can a function return ? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

How many values can a function return ?

please help

17th Nov 2016, 6:00 AM
Bhairesh M
Bhairesh M - avatar
6 Antworten
+ 4
c++ does not allow to return an multiple data as return to a function. However, you can return a pointer to an array by specifying the array's name without an index. You can also use static keyword. If an array is static it can return as an array but it should store in pointer which will be array data type.
17th Nov 2016, 9:31 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 2
in which programing language?
17th Nov 2016, 6:25 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 1
you can return just one value with the option of many values. example:- string strVal(int a, int b) { string aboveTen = "The sum is above 10"; string belowTen = "The sum is below 10"; int sum; sum = a + b; if(sum >= 10) return aboveTen; else return belowTen; } NB: If you have just one statement to execute after the if-else statement, you dont need to add curly brackets "{}".
17th Nov 2016, 5:53 PM
Franky BrainBox
Franky BrainBox - avatar
0
C++
17th Nov 2016, 9:03 AM
Bhairesh M
Bhairesh M - avatar
0
ok bro..I understood..thanks..
17th Nov 2016, 9:36 AM
Bhairesh M
Bhairesh M - avatar
0
you could also return tuples if using c++11 and above
17th Nov 2016, 4:55 PM
Rill Chritty
Rill Chritty - avatar