Solved Pre-incrementation -> strange thing
-
Hey,
I have this code#include <QCoreApplication> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); int b = 1; int c = ++b + ++b; qDebug()<<c; b = 1; c = ++b + ++b + ++b; qDebug()<<c; b = 1; c = ++b + ++b + ++b + ++b; qDebug()<<c; b = 1; c = ++b + ++b; c += ++b + ++b; qDebug()<<c; return a.exec(); }
and I get this value
6 10 15 16
I cannot imagine why is such and no other result.
Someone can explain me? -
Hi,
Take a look at the here and its associated note about order of evaluation.
AFAIK, you're in the undefined behaviour territory.
-
Thanks, for reply.
I don't expect that this can be UB, even in my dreams :|.Anyway topic solved.