+ 1

How can I return two elements using function?

https://code.sololearn.com/cNeY9b8M2s1M/?ref=app Here in this code, I'm returning an array. But I also want to return n, which is the number of elements in the array. How can I return these two elements?

16th Jul 2021, 1:10 PM
Srinath
8 Réponses
+ 1
Martin Taylor what do you mean by passing the size variable as pointer in arguments? Do you mean by creating a new function by passing the arguments as the size and returning the size value again?
16th Jul 2021, 3:32 PM
Srinath
+ 1
You can use struct or union to do that
17th Jul 2021, 6:49 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
「HAPPY TO HELP」 can you please explain how can I implement it in my code, how can I pass in a variable by reference and overwrite it. Can you explain it more elaborately.
16th Jul 2021, 3:35 PM
Srinath
0
Martin Taylor Why did you call the argument with an address? array=getarr(&arraysize); And why are we declaring it as a pointer? int* getarr(int *sz); I think you are returning the value as you used the pointer again, *sz=50; But why aren't we just using int without pointers and address? Could you please explain this flow of code again and correct me if I'm wrong too.
17th Jul 2021, 3:51 PM
Srinath
0
Martin Taylor Thanks it works perfectly now. I got a bit confused as you passed *sz=50; as i originally asked to pass the value of n, which is the number of elements in the array :)
19th Jul 2021, 4:11 PM
Srinath