Q:

Result should be 11 after incrementing, it is 12, why?

using namespace std;
int main()
{    
    int n, *p1, *p2;
    n = 10;
    p1 = &n; 
    p2 = p1;
    (*p1)++;
    (*p2)++;
    cout << *p1 << " " << *p2 << " "<< n << endl ;      
    return 0;   
}

A:

*p1 refers to the value pointed by the pointer p1. (*p1)++ will increment the value of n by 1 and (*p2)++ will again do the increment on n, since it is pointing to the same location of p1. So the n will be incremented to 12. *p1,*p2 and n will thus have 12. So it prints 12.

