+ 3
Why ++i*++i is so weird
6 Antworten
+ 8
Avoid to use such types of calculations . This will give different Output in different plateform. I tried in program i was getting different Outputs in solo and other ide.
#include <iostream>
using namespace std;
int main() {
int i=2;
int c=++i*++i;
cout<<c;
return 0;
}
Some Compilers giving Output as 12 and some giving 16 so its depend on Compilers.
+ 5
shubham patil It's not always fixed!
In java =>
int x = 3;
System.out.println((++x)*(++x));
Output: 20
Because the second increment is happening after the 1st value has already been taken!
(++x)*(++x) => (3+1)*(4+1) => 20
But in C,
Both the increments are happening in the starting only!
So, (++x)*(++x) => (3+2)*(3+2) => 25
+ 4
shubham patil
Please read this 👇
This is how I came to understand that I should never mix a read and write operation in a single code execution sequence.
https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points
+ 1
Yeah ཞıɬıƙą ɱıʂɧཞą i tried on code::blocks an solo
Both i increases by 2 at a time and then get multiplied but there is no clear logic
+ 1
https://code.sololearn.com/cgxtDk5Z2fNr/?ref=app
Infinity thanks ... but still i get 49 as ans