Functions argument

You could also use a class kind of like a struct. That way you could also return different types of variables. But if they are of the same type, an array is probably more efficient.

PairOfValues test;
//PairOfValues test = new PairOfValues(5, 23.5);

void setup() {
 
  test = doubleHalf(3);

  println("Result : " + test.a + " and " + test.b);
  exit();
}



PairOfValues doubleHalf(int val) {
  int nr1 = val * 2;
  float nr2 = val / 2.0;
  return new PairOfValues(nr1, nr2);
}


final class PairOfValues {
  int a;
  float b;

  PairOfValues(int nr1, float nr2) {
    this.a = nr1;
    this.b = nr2;
  }
}

3 Likes