If I have a function that produces a result int and a result string, how do I return them both from a function?
As far as I can tell I can only return one thing, as determined by the type preceding the function name.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know what your
stringis, but I’m going to assume that it manages its own memory.You have two solutions:
1: Return a
structwhich contains all the types you need.2: Use pointers to pass out values.
Which one you choose to use depends largely on personal preference as to whatever semantics you like more.