+ 1

How can we return multiple values to a function?

20th Aug 2019, 6:18 AM
Sanjaya Acharya
Sanjaya Acharya - avatar
8 Answers
+ 5
you can use a struct or pointer to return multiple values from a function
20th Aug 2019, 7:19 AM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar
+ 4
Using pointers u can pass multiple parameters (i. e. Value of call by reference) and u can return multiple values also...
20th Aug 2019, 6:44 AM
Kuri
Kuri - avatar
+ 2
CarrieForle, wait. Was he talking about *passing arguments*? // multiple args int AddTwoNums(int a, int b) { return a+b; }
20th Aug 2019, 6:31 AM
Trigger
Trigger - avatar
+ 1
You can only return one value with a function. Though if you want to return multiple, you can pack them into an array or hashtable and return that
20th Aug 2019, 6:19 AM
Trigger
Trigger - avatar
+ 1
It means i can't use functions to swap multiple values?
20th Aug 2019, 6:22 AM
Sanjaya Acharya
Sanjaya Acharya - avatar
+ 1
You cant *return* multiple values from a function. You *can* change global variables
20th Aug 2019, 6:24 AM
Trigger
Trigger - avatar
+ 1
Thank you...
20th Aug 2019, 6:24 AM
Sanjaya Acharya
Sanjaya Acharya - avatar