I know how to do call by reference and call by pointer operations. But I am confused about doing both of them in pre and post-increment operation. Here the code snippet.
Call by reference with pointer arguments
void fun2(int *x) // It works like int *x=&x;
{
++*x; // *x++ does not provide lvalue, so will not work here [ I think So ]
}
Call by reference with reference arguments
void fun3(int& x)
{
++x; // x++; [both works fine but I can't understand why?]
}
Here's the Driver code
int main()
{
int x=10;
cout<<x<<"\n"; //10
fun2(&x);
cout<<x<<"\n"; //11
fun3(x);
cout<<x<<"\n"; //12
return 0;
}
Why in fun2() *x++ gives the output 10 instead of giving 11 but ++*x works fine and in fun3() both x++ and ++x works fine?