I'm confused. I would expect that the first print statement in the function would print 6 and not 5. Because a++ + c++ = (1+1) + (3+1) = (2+4 = 6).
#include <iostream>
#include <string>
int main()
{
int a = 1;
int b = 2;
std::cout << "intitialisation b:"<< b << std::endl;
int c = 3;
{
auto b = ++a + c++;
std::cout << "increment b in function:" << b << std::endl;
auto e = b;
c += ++b;
std::cout << "increment b in function:" << b << std::endl;
}
std::cout << "increment b out function:" << b << std::endl;
int* p = &a;
int* q = &b;
std::cout <<"value pointer:" << *q << std::endl;
++(*q);
std::cout <<"value pointer:" << *q << std::endl;
*p += a++ + (*p)++;
}
intitialisation b:2
increment b in function:5
increment b in function:6
increment b out function:2
value pointer:2
value pointer:3
Nadine