[C] 利用 struct 回傳多個參數

/* 利用 struct 回傳多個參數 */

#include <stdio.h>
#include <stdlib.h>

// 定義新的變數型態 struct num
struct num{
    int v1, v2;
};


// 副函式:回傳新的變數型態 struct num
struct num oper(struct num);


// 主函式
int main()
{
    struct num XandY, result;
    XandY.v1=1;
    XandY.v2=2;
   
    result = oper(XandY);
    printf("%d , %d\n", result.v1, result.v2);
   
    system("pause");
    return 0;
}

struct num oper(struct num XandY)
{
    struct num CandD;
    CandD.v1 = XandY.v1;
    CandD.v2 = XandY.v2;
   
    return CandD;
}