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

前端 未结 8 1096
深忆病人
深忆病人 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:03

    By passing parameters by reference to function.

    Examples:

     void incInt(int *y)
     {
         (*y)++;  // Increase the value of 'x', in main, by one.
     }
    

    Also by using global variables but it is not recommended.

    Example:

    int a=0;
    
    void main(void)
    {
        //Anything you want to code.
    }
    

提交回复
热议问题