函数在C&中返回两个值C ++ [英] Function returning two values in C & C++

查看:63
本文介绍了函数在C&中返回两个值C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++和C编程语言中,是否有可能从函数返回两个值?
请帮助我,这是我的面试问题.

In C++ and C programming languages is there any possibility for returning two values from a function?
Please help me, it''s my interview question.

推荐答案

如果您不足够通过面试,则无法在此处获得特定问题的答案找你一份工作.他们并非都提出相同的问题,而他们所做的只是暴露出您缺乏基本的C ++知识,这是没有任何一个问题可以帮助您的.

您可以将一个对象作为指针传递,然后在您的方法中对其进行更改将在方法之外对其进行更改.您还可以返回自己的结构,该结构具有要返回的成员,或者如果只有两个成员,则STL具有可以使用的pair类.如果对象的类型相同,则还可以返回容器类,或仅返回指向对象列表的指针.
If you don''t know enough to pass your interview, getting answers to specific questions here will not get you a job. They don''t all ask the same questions, and what they''ve done is expose your lack of basic C++ knowledge, something that no single question will help you with.

you can pass an object in as a pointer, and then changing it in your method will change it outside the method. You can also return your own struct that has the members you want to return, or if there''s only two of them, the STL has a pair class you can use. If the objects are of the same type you can also return a container class, or just a pointer to a list of objects.


从字面上看说不.
但是,没有什么可以阻止一个值是复合的"并且其中包含更多的值.
更不用说参数可以被引用,被引用的对象可以用作返回值的事实.
Literally speaking no.
But nothing prohibits a value to be "composite" and have more values in it.
Not to mention the fact that parameters can be reference, and the referred objects may be used as return values.


始终可以从函数中返回struct或指向struct的指针.在C ++中,您还可以返回pair<first_type, second_type>;)
It is always possible to return struct or pointer to struct from function. In C++ you can also return pair<first_type, second_type> ;)


这篇关于函数在C&amp;中返回两个值C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆