x=x+(3*2) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

x=x+(3*2)

x=2 and result is 8,but they write 7

25th Jan 2019, 6:08 PM
aurelcik
aurelcik - avatar
9 Answers
+ 2
#include <stdio.h> int main() { int x = 2; x += 1; // x is now 3 x -= 1; // x is now 2 x *= 3; // x is now 6 x /= 2; // x is now 3 x %= 2; // x is now 1 x += 3 * 2; // x is now 7 printf("%d", x); return 0; }
25th Jan 2019, 6:28 PM
Seb TheS
Seb TheS - avatar
+ 1
But x has changed value to 1.
25th Jan 2019, 6:25 PM
Seb TheS
Seb TheS - avatar
+ 1
x was 2, but it changed value.
25th Jan 2019, 6:27 PM
Seb TheS
Seb TheS - avatar
+ 1
... x %= 2; // x=1 x += 3*2; // x+=6 1 + 6 == 7
25th Jan 2019, 6:28 PM
Diego
Diego - avatar
0
Are you sure you didn't type x+(2+3)?
25th Jan 2019, 6:19 PM
Seb TheS
Seb TheS - avatar
0
#include <stdio.h> int main() { int x = 2; x += 1; // 3 x -= 1; // 2 x *= 3; // 6 x /= 2; // 3 x %= 2; // 1 x += 3 * 2; // 7 printf("%d", x); return 0; }
25th Jan 2019, 6:22 PM
aurelcik
aurelcik - avatar
0
int x=2; it's condition
25th Jan 2019, 6:26 PM
aurelcik
aurelcik - avatar
0
😀Thanks
25th Jan 2019, 6:29 PM
aurelcik
aurelcik - avatar
0
If x = 2 then x=x+(2*3) = 8 2*3=6+2= 8
25th Jan 2019, 8:06 PM
D_Stark
D_Stark - avatar