c Language operator questions

Asked 2 years ago, Updated 2 years ago, 60 views

include < stdio.h>

int main(void){

a=63, b=1, c=11, d=8, e=28;

d %= c += 5 - d--;

printf("%d %d %d %d %d", a,b,c,d,e);

return 0;}

Why does the value of d come to -1 when you turn the code to?

When calculating by hand, we got 7 but if we implement it as visual studio, we get -1.

I want to know how -1 comes out~

operator

2022-09-20 17:41

1 Answers

d %= c += 5 - d--;

is the same as running the following two lines sequentially.

d%=(c+=5-d);
d--;

Then you can solve it as below. d%=(c+=5-d); becomes d%=(c+=(-3) because d is 8, and c becomes because is 11.

Therefore, the expression above is as follows.

d%=8;
d--;

Since d is 8, d%=8 will be 0, and then d-- will finally be -1.


2022-09-20 17:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.