题目如下:
In a programming language with only two levels of operator precedence — unary binding tighter than binary — and left-to-right evaluation, what is the value of the following expression?
– 7 – – 5 * – 4 + 3 * 2
A. 4
B. 22
C. -21
D. -33
翻译下:
某种编程语言只有两种运算符优先级,一元运算符比二元运算符有更强的结合性,并且运算顺序从左到右,下面表达式的计算结果是什么?
A. 4
B. 22
C. -21
D. -33
我有两种运算符优先级,但是也没指明乘法和除法优先级高于加减法啊,所以不知道怎么下手,求指点
------解决方案--------------------------------------------------------
我选B,– 7 – – 5 * – 4 + 3 * 2
一元运算优先于二元运算,得到
(– 7) – (– 5 )* (– 4) + 3 * 2
按照从左往右计算(加减乘除运算优先级一样)
1. -7-(-5)=-2
2. -2*(-4)=8
3. 8+3=11
4. 11*2=22
------解决方案--------------------------------------------------------
C. -21
------解决方案--------------------------------------------------------
– 7 – (– 5) * (– 4) + (3 * 2)
– 7 –
(– 5) * (– 4) + -- 20
(3 * 2) -- 6
-7 - 20 + 6 = -21
------解决方案--------------------------------------------------------
我同意楼上的
– 7 – (– 5) * (– 4) + (3 * 2) = -7-20+6=-21
------解决方案--------------------------------------------------------
求答案,答案