+ 1
Function returning ?
How to return addition subtraction multiplaction of tow values(a,b) at same time from a function ?
2 Respostas
+ 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.
+ 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).