Can we return two values from a single function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can we return two values from a single function?

Can we return two different values from a single function? Is that even posible...

8th Jan 2019, 10:24 AM
Shubhendu
Shubhendu - avatar
3 Answers
+ 1
Depending on the language you want to use (please specify it in the tags next time 😊) - yes. But it also depends on the way your function works. If you just want to print values you could do that with as many as you need. But if you need to return them you will need some kind of a container (in C++ at least, please note specifying the language next time 😊). If it is C++ please use the following link for more details : https://stackoverflow.com/questions/6394741/can-a-c-function-return-more-than-one-value
8th Jan 2019, 11:12 AM
Denis Cvetanov
Denis Cvetanov - avatar
+ 1
It's c++ Got it We can use structure here..
8th Jan 2019, 11:20 AM
Shubhendu
Shubhendu - avatar
+ 1
Excellent, then you can look up the link and choose the method which you consider easier or best to implement. Good luck!
8th Jan 2019, 11:23 AM
Denis Cvetanov
Denis Cvetanov - avatar