C function arguments are passed by value. This means that instead of passing the stage reference, you are passing the value stored in it. The update that you perform in the changeStage function then only applies to the copy that was made.
If you want to update a variable in another function, you will need to pass a pointer to it.
void changeStage(int* stage_p){ *stage_p = 1; } int main() {
&stage says it takes the address of stage and passes it to the function. The stage_p argument stage_p then point to int in the main.
*stage_p forces you to use the value specified in stage_p , which stage is mainly in your case.
Further reading
Ryan haining
source share