a+=b>=300?b=100:a==100;
If aand bare initialized to 100and 200accordingly, what are the values aand bafter the ternary operator?
a
b
100
200
The answer was a=101, b=200.
a=101
b=200
How is this possible?
Just add some parentheses and spaces to make them more readable, and this should be obvious:
a += ((b >= 300) ? (b = 100) : (a == 100));
(Refer to table C to find out why the brackets can be placed where they are in the above expression.)
So this is essentially true:
a += 1;
, . a += a==100. a += 1, == 1 = true.
a += a==100
a += 1
, :
a += b >= 300 ? b = 100 : a == 100;
C ( java javascript-):
a += (b >= 300) ? b = 100 : a == 100 ;
b = 200, b >= 300 false, , a == 100 1 a 100. 1 a, a 101. b .
b = 200
b >= 300
a == 100
1
101
Source: https://habr.com/ru/post/1679102/More articles:3D Touch Peek and Pop by UITableViewCell Objective-C Code. (Force Touch) - iosHow to create a pulsed effect on the image in a few seconds when loading the page? - jqueryORA-01735: invalid parameter ALTER TABLE - Toad - sqlBad variable - jsonHow to remove multilevel index in pandas pivot table - pythonsed replace group of lines of files - linuxCalculate the number of files in a folder in a complex folder structure? - rjava.util.ConcurrentModificationException - javaDecimalFormat does not work properly after updating windows - java(Docker) Getting the error: docker-php-source: there is no such file or directory when creating the docker file - phpAll Articles