Function returning ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Function returning ?

How to return addition subtraction multiplaction of tow values(a,b) at same time from a function ?

4th Mar 2022, 5:03 AM
A Rahman Mamnoon
A Rahman Mamnoon - avatar
2 Answers
+ 3
Pass an array to the function and assign the results of your arithmetic to the elements of that array, or pass three pointers and assign the results to the pointer. In C++ you can use reference variable.
4th Mar 2022, 6:58 AM
rodwynnejones
rodwynnejones - avatar
+ 1
Assuming <a> and <b> was function arguments, <T> as the arguments' type, and you want to *return* the results ... You can create, fill and return a pointer of <T> which refers to a memory block large enough to store 4 <T> values (storing results from addition, subtraction, multiplication and division of the 2 arguments given) The caller receives the pointer, and iterates through it to fetch and/or display each operation result. The caller will be responsible for resource cleanup (deallocation of memory).
4th Mar 2022, 7:33 AM
Ipang