The order in which elements are evaluated in an expression is unspecified, except in some very special cases, such as && and || and etc.
recording:
cout<< "i = "<< i << "n*n = "<<n*n<< "n++ = "<< n++<< " *p "<<endl;
you assume the order and, in particular, that n ++ is the last evaluated.
To solve this problem, you can divide the expression into two parts:
cout<< "i = "<< i << "n*n = "<<n*n<< "n++ = "<< n<< " *p "<<endl; n++;
source share