the program behaviour is different with code that have similar function
this
#include <iostream>
#include <string>
int main()
{
int a = 1;
while (a < 11)
{
int b = a++;
int c = a * b;
std::cout << c << std::endl;
++a;
}
return 0;
}
/* result:
* 2
* 12
* 30
* 56
* 90
*/
and this one
#include <iostream>
#include <string>
int main()
{
int a = 1;
while (a < 11)
{
int b = a + 1;
int c = a * b;
std::cout << c << std::endl;
++a;
}
return 0;
}
/* result:
* 2
* 6
* 12
* 20
* 30
* 42
* 56
* 72
* 90
* 110
*/
I thought that only ++a would not work because it's equivalent as "a = a + 1"
while a++ would equivalent "a + 1", or what I miss?
-vastor