How to return different types from a single function

前端 未结 5 1616
[愿得一人]
[愿得一人] 2020-12-18 15:57

I have the following c code :

#include 
#include 

void *func(int a) { 
    if (a==3) {
        int a_int = 5;
        int *pt         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 16:22

    If you want a function that return two (or more) values, you have two possibilities:

    1- Make the function void and return the values as parameters by reference &

    2- Declare a struct (or class) that groups the values and make the function return a value of this struct.

提交回复
热议问题