Returning multiple values from a C function

前端 未结 11 1101
醉话见心
醉话见心 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 09:04

    Easiest to read should be passed addresses in the function, and it should be fast also, pops and pushes are cheap:

    void somefunction (int inval1, int inval2, int *outval1, int *outval2) {
       int x = inval1;
       int y = inval2;
    // do some processing
       *outval1 = x;
       *outval2 = y;
       return;
    }
    

提交回复
热议问题