why is 'c' == 'd' + 1 && 2 < 4 logical true but 'c' == 'd' - 1 && 2 < 4 logical false

2 views (last 30 days)
I dont understand how +1 or -1 affect the result

Answers (1)

Image Analyst
Image Analyst on 24 Mar 2019
Huh? Did you get that right?
b1 = 'c' == 'd' + 1 && 2 < 4
b2 = 'c' == 'd' - 1 && 2 < 4
b1 =
logical
0
b2 =
logical
1
>> doc precedence
You'll see that + and - come before == in precedence so 'd' + 1 is 'e', and 'd'-1 is 'c' so the equations become
b1 = 'c' == 'e' && 2 < 4
b2 = 'c' == 'c' && 2 < 4
so the first one is false && true, which is false, and the second one is true && true, which is true, just as it comes out in the command window as I showed above.

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!