Returning multiple values from a C function

前端 未结 11 991
醉话见心
醉话见心 2021-01-18 08:05

Important: Please see this very much related question: Return multiple values in C++.

I\'m after how to do the same thing in ANSI C? Would you use a

11条回答
  •  无人共我
    2021-01-18 08:58

    Both ways are valid, certianly, but I would would consider the semantics (struct vs parameter reference) to decide which way best communicates you intentions to the programmer.

    If the values you are returning are tightly coupled, then it is okay to return them as a structure. But, if you are simply creating artificial mechanism to return values together (as a struct), then you should use a parameter reference (i.e. pass the address of the variables) to return the values back to the calling function.

提交回复
热议问题