Web Page - http://www.cs.tau.ac.il/~efif/courses/ComputerProgramming
| expression | operator | operand(s) |
|---|---|---|
| (a + b) * c | * | (a+b), c |
| (a+b) | () | a+b |
| a+b | + | a, b |
| a | ||
| b |
A reference to a location, an expression which can appear as the destination of an assignment operator indicating where a value should be stored. For example, a variable or an array element are lvalues but the constant 42 and the expression i+1 are not.
int i; |
i = 1; |
| legal: | i = 1 |
| illegal: | i + 1 = 2 |
int a = 1; double b = 7.35; double c; c = a + b; |
int a = 1; double b = 7.35; double c; c = a + b; |
/* lower: convert character to lower case (ASCII only!) */
int lower (int c)
{
if (c >= 'A' && c <= 'Z')
return c + 'a' - 'A';
else
return c;
}
|
int a, b, c; c = a % b; |
| Precedence | Associativity | Operator |
|---|---|---|
| 13 | left | *, /, % |
| 12 | left | +, - |
if (year % 4 == 0)
printf ("%d is a leap year\n", year);
else
printf ("%d is not a leap year\n", year);
|
int i = 12; int j; j = ++i; |
int i = 12; int j; j = i++; |
unsigned int i = 0; i--; |
| Precedence | Associativity | Operator |
|---|---|---|
| 15 | left | ++, -- (post) |
| 14 | right | ++, -- (pre) |
| 13 | left | *, /, % |
| 12 | left | +, - |
int numCalls = 0;
int count (void)
{
return numCalls++;
}
|
i = j = k = 37; |
| a += b | a = a + b |
| a -= b | a = a - b |
| a *= b | a = a * b |
| a /= b | a = a / b |
| a %= b | a = a % b |
| Precedence | Associativity | Operator |
|---|---|---|
| 15 | left | ++, -- (post) |
| 14 | right | ++, -- (pre) |
| 13 | left | *, /, % |
| 12 | left | +, - |
| 2 | right | =, +=, -=, *=, /=, %= |
i = j + 75; |
| versus |
|
| Precedence | Associativity | Operator |
|---|---|---|
| 15 | left | ++, -- (post) |
| 14 | right | ++, -- (pre) |
| 13 | left | *, /, % |
| 12 | left | +, - |
| 10 | left | <, >, <=, >= |
| 2 | right | =, +=, -=, *=, /=, %= |
unsigned int i = 0;
if (i > -1) {
(some code …)
}
|