Fail to return int value from a function
the parameters of a function call are copied into parameters in the function. if the pointer is copied it still points to a memory where you write the data. if int is copied then changing the value changes the copy, not the variable used as parameter. reference is kind of pointer

how to make an in-out parameter by passing a parameter by reference

void setup() {

  Serial.begin(115200);
  int x = 3;
  fnc(x);
  Serial.println(x);
}

void loop() {

}

void fnc(int &amp;x) {
  x = 5;
}


prints 5    

example with a complex type

#include &lt;IPAddress.h&gt;

void setup() {

  Serial.begin(115200);
  IPAddress ip(192, 168, 1, 5);
  fnc(ip);
  Serial.println(ip);
}

void loop() {

}

void fnc(IPAddress&amp; ip) {
  ip = IPAddress(192, 168, 1, 3);
}


with &amp;ip it prints 192.168.1.3. without &amp; it prints 192.168.1.5