some questions of complex

Please read this program
When I run this program, I find that the result of the sentence:a=*p+*++p is out of my expectation, I think the result is that a.real()=4 and a.imag=6. But when I debug this program the result is something I can not understand.
Please help me to find the root of the problem.
Thanks!
#include<iostream>
#include<complex>
using namespace std;
void main()
{
complex<double>a(2, 3);
complex<float>b(0, 3);
complex<int>c;
complex<double>d(a);
complex<double>e[2]={complex<double>(1, 2), complex<double>(3, 4)};
complex<double>*p = &e[0];
a+=d;
cout<<a<<endl;
a=*p+*++p;
cout<<a<<endl;
double x = a.real();
double y = a.imag();
cout<<x<<" "<<y<<endl;
}
a=*p+*++p;

You cannot do this. The result is undefined.

See this thread for details:

http://www.cplusplus.com/forum/general/70176/
a=*p+*++p
The result of this expression is undefined. To make it defined, refactor it to one of these, depending on what you meant to do:
1.
1
2
p++;
a=*p+*p;

2.
1
2
a=*p+*(p+1);
p++;
Topic archived. No new replies allowed.