Search code examples
cfunctionreturn-valuemultiple-return-values

Returning two values at the same time in a function


How can I return two integer type values at the same time in one function in the C programming language or should I write two different functions?


Solution

  • You can create a struct in which you have two integers and return this struct as the result of your function.

    In a language such C, you can store your data in struct like this :

    struct foo {
     int x;
     int y;
    }