Modifying the same variable inside the same statement like that is not reliable. Split it into separate statements (lines) and it should give you the result you expected.
For the future you might want to turn up the compiler's warning level so that it can warn you about problems like this. If you're using GCC (or MinGW on Windows) you should at least use the -Wall compiler flag.
Thank You friend but when i compiled this same program in my android phone (Application: C4droid (GCC compiler for android)) then it worked successfully.
Why is this happening?
Modifying the same variable inside the same statement like that is not reliable. Split it into separate statements (lines) and it should give you the result you expected.
I think the code might act differently if compiled by different compilers. It is just better if you write it in separate statements.
1 2 3 4 5 6 7 8 9 10 11
#include<iostream>
usingnamespace std;
int main() // Does the code compile?
{
int a=7;
cout << a++;
cout << a++;
cout << a;
}
I have compiled statements like these on C4Droid too. I am surprised I finally met someone on here who uses it too.
See, modifying the same variable and using it in the same statement is undefined. This means you will get different results on different compilers/machines.