用于返回结构的函数名称

Yíu*_*Yíu 0 c struct

我想创建一个函数,我在其中更改已存在的结构.所以该函数的返回值应该是一个struct.如果我想要一个int返回值,我调用函数" int example()"...如果我想返回一个结构,如何调用该函数?由于"struct"已经被采用 - 我已经用" struct whatever"来创建一个.

nne*_*neo 7

如果希望函数修改现有结构,则应该通过指针传递结构:

void modify_thing(struct whatever *thing);
Run Code Online (Sandbox Code Playgroud)

如果要返回结构的修改副本,可以按值返回结构:

struct whatever edit_thing(const struct whatever *input);
Run Code Online (Sandbox Code Playgroud)

请注意,通过指针而不是值传递结构变量通常更有效.