0

Requesting explanation of the following c program. The output is 36 and 63, but how?

int a=10, b=25; a = b++ + a++; b = ++b + ++a; printf("%d %d",a,b); }

6th Dec 2019, 2:58 AM
Ayush Bharti
3 ответов
0
at 1st, a= b++ + ++a (here b=25,a=10 after sum a=35) b = ++b + ++a( here b=27 ,a=36, after sum b= 63) so, when print the value then a=36, b=63
6th Dec 2019, 3:53 AM
MD. TANVIR AKTER SHAON
0
int a=10, b=25; //note: a++ is used, increment is after the variable a = b++ + a++; //result for a is 35 //b and a here are secretly/already incremented to (b=26, a=11)but cannot reflect value directly to a, the new values of b&&a can only be used on next variable //note: ++a is used, increment before the variable b = ++b + ++a; //first, we can now use the new value of (b) which is 26 then incremented again to (b=27) by ++b but, unlike to the first statement, here, it directly used the new value. Second, the new value of (a) was 35 but incremented by ++a then, the newest value is (a=36). printf("%d %d",a,b);//so, a=36 and b = 36+27; :hope it helps, im looking for friends, im a 2nd yr student bscpe
6th Dec 2019, 4:26 AM
Sunday Conde
Sunday Conde - avatar
0
This is *COMPLETELY* compiler dependant as modifying a variable more than once in the same statement is undefined behavior
6th Dec 2019, 10:52 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar