++i*++i*++i

#include <stdio.h>
int main()
{
int i=2;
printf("%d",++i*++i*++i);
return 0;
}

on execution of the above program
Why am i getting the answer as 80? //i am using codeBlock ide 17.12
i expected to get the answer as 125Now i am confused with the working of the pre-increment in the statement printf("%d",++i*++i*++i); of the above program

Try it on the different compiler of c language itself, you’ll get different answers and they will also give you warnings. Why? This is an undefined behaviour. Compiler here with compiler warnings on https://rextester.com/l/c_online_compiler_gcc. Why? You are writing to the same memory location more than once between two sequence points. This invokes Undefined Behavior. You can read more here Stack Overflow.

2 Likes

thank you brij_raj,your answer helped me alot
Couldn’t upvote your answer i have no enough reputation points