+ 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?
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?
+ 1
You can use struct or union to do that
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.
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.
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 :)