For some reason when doing few calculations, I am getting the output that is not what was expected.
Here we calculate b from a=5, why are the outputs of b being different and why is it 28 when it should be 26 (12+14) but is it being 26 when done separately. Even after removing the brackets when calculating in one line, it gives the same output (28)
The code for the calculations that I did-
int main()
{
int a, b;
a = 5;
b = 2 * ++a; //first part of the calculation
std::cout << a << std::endl;
std::cout << b<<std::endl;
b =b+2 * ++a; //second part of the calculation
std::cout << a << std::endl;
std::cout<<b<<std::endl; //It is coming as 26 when done separately
//RESTARTING THE OPERATION FROM SAME VALUES TO FIND B IN ONE LINE
a = 5;
std::cout << 2 * ++a << std::endl;
std::cout << 2 * ++a << std::endl;
a = 5;
b = (2 * ++a) + (2 * ++a); //b being calculated in one line
std::cout << a << std::endl;//But 28 when done in one line
std::cout << b;
return 0;
}