I am trying to learn 'call by reference'. I want to call a function fcn1
from the main loop and pass a reference of the local variable var
to the function fcn1
. Next step is to call a second function fcn2
from the function fcn1
and pass again the reference of the local loop variable var
. I always get this error massage:
invalid conversion from 'int' to 'int*' [-fpermissive]
Here a small example code:
void fcn1(int *variable)
{
fcn2(&variable);
}
void fcn2(int *variable)
{
//do something with the variable
}
void setup()
{
}
void loop()
{
int var = 1000;
fcn1(&var);
}
I tried to solve that issue by using:
void fcn1(int *variable)
{
fcn2(*variable);
}
But it's the same error.
By deleting the *
respectively &
it works fine, but is it still a reference?