Is there a way to create a function in an arduino code with int or void or a boolean array that will output multiple values? Is there a usful example you have
Some options:
- Return a struct.
- Return an
std::array
. - Return an
std::pair
orstd::tuple
.
Example:
// 1.
struct IntAndABool {
int value; // use meaningful names in your code
bool flag;
};
IntAndABool some_function(int a, int b) {
return {a + b, a > b};
}
// 2.
#include <array>
std::array<int, 3> some_other_function(int i) {
return {i+1, i+2, i+3};
}
// 3.
#include <tuple>
std::tuple<int, bool> a_third_function(int a, int b) {
return {a + b, a > b};
}
// 4.
void yet_another_function(int a, int b, int &value, bool &flag) {
value = a + b;
flag = a > b;
}
2 Likes
- Return via reference (s)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.