0
x -= 1; // 2 x /= 2; // 3 x %= 2; // 1
Why did they happen like that İf we think like normal math, for the first example 2+1=1 should be like that Second example : 2/2=1 should be like that and Thirth example : 2%2=0 but why the Outputs are 2,3,1
2 Respuestas
+ 5
The compound assignment operators are shortcuts. This:
x = x + (expression);
can be shorten to:
x += expression;
It means calculate x + (expression) and replace the current value of x with the result.
0
Thank you for your answer.
Actually I was talking about the example which is given
The whole code was:
#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;
}
and I did not understand examples I mentioned above