01: // precedenza e associativita' operatori
02: #include<stdio.h>
03: #include<stdlib.h>
04:
05: int main()
06: {
07:
08: int a = 20;
09: int b = 10;
10: int c = 15;
11: int d = 4;
12: int e;
13:
14: // * and / operators have precedence wrt + and -
15: // but * and / in which order are computed? And why? Associativity!
16: e = a + b * c / d;
17: printf("Value of a + b * c / d is: %d\n" , e );
18:
19: e = (a + (b * (c / d)));
20: printf("Value of (a + (b * (c / d)) is: %d\n", e );
21:
22: e = (a + ((b * c) / d));
23: printf("Value of (a + ((b * c) / d)) is: %d\n", e );
24:
25:
26: // associativity right to left
27: e = ( a = b = c = d );
28: printf("Value of a = b = c = d is: %d\n", e);
29:
30: return 0;
31: }
32:
Se avete commenti o osservaƶioni su questa pagina
mandate un messaggio di posta elettronica a bertoƶƶi@ce.unipr.it
mandate un messaggio di posta elettronica a bertoƶƶi@ce.unipr.it