Ok, i'm a bit confused with passing a pointer to a function e.g.
void change_val(int *var, int val)
{
*var = val;
}
int main(void)
{
int a = 5;
int *p = &a;
p = &a;
cout << "*p: " << *p << endl;
change_val(p, 10);
cout << "*p: " << *p << endl;
return 0;
}
Most text i read say if you want to change the value of a pointer passed to a function you have to declare the parameter as a pointer to a pointer (int **var) and pass the pointer memory address (&p). So how does the above program work?
Thanks for any help.