Execution order of programs code is very much a vital thing to understand and where some fault finds will take a long while to figure out. Basically like in maths where there is a order of calculating, well in coding structures and also multitasking and multi-threading setups the execution order may be incorrect for lines of code.
Here is some examples, the first is when will a function be called and the later when post/pre incrementation will take place.
#include <iostream> using namespace std; int value =1; int setvalue2() { cout << "setting value"<<endl; value = 2; return value; } int returnvalue() { cout << "renting value"<< endl; return value; } int main() { // depending on the order of execution the value may be /* setvalue2 called first (setvalue2 = 2 / returnvalue = 2) = 1 returnvalue called first (setvalue2 = 2 / returnvalue = 1) = 2 */ cout << setvalue2() / returnvalue() << endl; int i; i = i++ - ++i; // not sure what i will be because the pre/post increaments i = 3, i++, i++; // i will equal 5 because in correct order. } |