A few questions on C++ (from my C++ textbook)

a void function can "return" a value. Example:
there's two ways to return more than one variable. The first is to make a struct to hold two values and return the struct:

struct fooReturn {
  int x;
  int y;
  int z;
};
fooReturn foo(int x, int y) {
  fooReturn ret = {x, y, x+y};
  return ret;
}
void setup() {
  Serial.begin(115200);
  fooReturn fr;
  fr = foo(3, 6);
  Serial.print("Sum is ");
  Serial.println(fr.z);
}
void loop() {}

The other is to pass the function an argument telling it where in memory to put the return value. This is called a pointer.

void foo(int* z, int x, int y) {
  *z = x + y;
}
void setup() {
  Serial.begin(115200);
  int z;
  foo(&z, 3, 6);
  Serial.print("Sum is ");
  Serial.println(z);
}
void loop() {}

In C++ there's also references which can do the same with slightly different syntax, but it's not advisible because the person calling the function won't know if it could change the value. But here's an example:

void foo(int& z, int x, int y) {
  z = x + y;
}
void setup() {
  Serial.begin(115200);
  int z;
  foo(z, 3, 6);
  Serial.print("Sum is ");
  Serial.println(z);
}
void loop() {}