How do I return multiple values from a function in C?

前端 未结 8 1094
深忆病人
深忆病人 2020-11-22 15:14

If I have a function that produces a result int and a result string, how do I return them both from a function?

As far as I can tell I can

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 16:02

    Create a struct and set two values inside and return the struct variable.

    struct result {
        int a;
        char *string;
    }
    

    You have to allocate space for the char * in your program.

提交回复
热议问题