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; }

5th Apr 2024, 4:37 AM
Sharanabasappa
Sharanabasappa - avatar
2 odpowiedzi
+ 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;
5th Apr 2024, 5:57 AM
Blud PlayingGames
Blud PlayingGames - avatar
+ 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.
5th Apr 2024, 10:53 AM
Tibor Santa
Tibor Santa - avatar