是否可以在 C 中返回两个变量?
我想返回一个指针和一个字符串,这样我就可以在函数之外使用它们。
这是用数组完成的吗?如果是这样,它将是什么类型的数组?无效?
最佳答案
不可以,您只能返回一个对象。但是,您可以返回结构类型对象,并且可以将“多次返回”放入结构中:
typedef struct return_type
{
void* pointer_; // You should, of course, use whatever the appropriate types
char* string_; // are for the objects that you are trying to return.
};
return_type f();
关于c - C中的双重返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4982431/