c語言 運算元 - 考試

By Oliver 
at 2017-05-10T00:24
at 2017-05-10T00:24
Table of Contents
int abc(int *k) { 
*k += 4;
return 3 * ( *k) - 1;
}
void main() {
int i = 10, j = 10, result1, result2;
result1 = (i / 2) + abc( &i);
result2 = abc( &j) + (j / 2);
}
如果在運算式中的運算元估算的順序是由右到左,則result1,則result2的值為何?
 
看了補習班答案是 result1=48, result2=46
 
result1= (i/2) + abc(&i)
= (14/2) + 41 (*k=14; 3*14 - 1=41)
= 48
 
想問的是,為什麼在abc裹的計算是先乘除後加減呢
而不是由右到左推算呢
因為本題沒有提運算子優先權,是不是應該照題目要求一律從右到左呢
 
謝謝
 
 
 
--
    *k += 4;
return 3 * ( *k) - 1;
}
void main() {
int i = 10, j = 10, result1, result2;
result1 = (i / 2) + abc( &i);
result2 = abc( &j) + (j / 2);
}
如果在運算式中的運算元估算的順序是由右到左,則result1,則result2的值為何?
看了補習班答案是 result1=48, result2=46
result1= (i/2) + abc(&i)
= (14/2) + 41 (*k=14; 3*14 - 1=41)
= 48
想問的是,為什麼在abc裹的計算是先乘除後加減呢
而不是由右到左推算呢
因為本題沒有提運算子優先權,是不是應該照題目要求一律從右到左呢
謝謝
--
Tags:
        考試
        
All Comments

By Olive 
at 2017-05-13T02:35
at 2017-05-13T02:35

By Oscar 
at 2017-05-14T08:32
at 2017-05-14T08:32

By Christine 
at 2017-05-17T16:17
at 2017-05-17T16:17

By Catherine 
at 2017-05-18T08:56
at 2017-05-18T08:56

By Kama 
at 2017-05-22T19:00
at 2017-05-22T19:00

By Tracy 
at 2017-05-25T06:49
at 2017-05-25T06:49

By Kumar 
at 2017-05-27T21:13
at 2017-05-27T21:13

By Eartha 
at 2017-05-28T21:43
at 2017-05-28T21:43

By Hedy 
at 2017-05-31T21:12
at 2017-05-31T21:12

By Jacky 
at 2017-06-04T11:30
at 2017-06-04T11:30

By Andy 
at 2017-06-09T11:12
at 2017-06-09T11:12

By Hedwig 
at 2017-06-14T03:18
at 2017-06-14T03:18

By Una 
at 2017-06-16T05:56
at 2017-06-16T05:56
Related Posts
中會單科函授選擇

By Edward Lewis 
at 2017-05-09T22:45
at 2017-05-09T22:45
民總錯誤與善意取得

By Annie 
at 2017-05-09T20:10
at 2017-05-09T20:10
推薦票據法老師或課本

By Caitlin 
at 2017-05-09T19:33
at 2017-05-09T19:33
三繞組變壓器之等效標么阻抗

By Mason 
at 2017-05-09T18:28
at 2017-05-09T18:28
基本電學

By Harry 
at 2017-05-09T18:25
at 2017-05-09T18:25