0
What is the output of the below code?
#include <stdio.h> int main(){ int i=1,j; j= (i++)*(++i); printf("%d",j); return 0; }
2 Answers
+ 1
Well the answer is 3 because .. the use of post increment and pre increment in the same operation lead to double side effect.. one for. I++ and another for ++I .. but it's depend very much on compiler and what optimization you , or the compiler use.. and it can lead to undefined behavior.. so.. for short.. the answer is j = 1 * 3;
+ 1
The correct answer is that you should never write code like this, exactly because the ambiguity, that for someone reading the code, it is difficult to guess the intent of the developer.