Expressions and operators
Arithmetic.... + - * / % ++ --
Logical.........<
<= > >= == !=..|| &&
!
Bit.............&
| ^ ~ ..<< >>
Assignment....
=.. += -= *= etc.
Conditional...(expr)?..value1:..value2
Pointer.........*
& -> . sizeof
Type............(type)
var...or...(type)(expr)
Division / produces an int if both operands are int, otherwise float.
a%b is a mod b, the remainder after dividing a by b.
++b means preincrement; a.=.++b; is equivalent to.b=b+1;. a=b;
b++ means postincrement; a = b++; is equivalent to a=b; b=b+1;
Use == to test for equality, not = (assignment operator).
&& is short-circuit and; a &&
b means "evaluate a; if it's false,ignore
b
....and produce a
false value, otherwise evaluate b and return its (logical)
....value".
The first four bit operators are, in order, And, Or, Exclusive Or, Comple-
....ment, each taken bitwise.
a<<3 means a shifted left 3 bits (multiplied by 8). >> is right shift.
a += 5; is equivalent to a = a+5;.
A conditional evaluates expr; if it's true, it evaluates
value1, otherwise it
....evaluates value2.
sizeof(type name) computes the number
of bytes needed to represent a
....value of the named type.
A type cast (int) (x/y) coerces a value
into the named type.
Examples
Arithmetic
....a+1
....offset%2
....++n
....n++
Logical
....x>0
....(k<n) && (A[k]==key)
....!found
Bit
....status & mask
....1 << offset
Assignment
....sum += A[k];
....status | = OVERFLOW;
Conditional
....max = (a>b)? a : b;
....tax = (income>100000)? 0 :(income>50000)?
10000
........: income;
Pointer
....p = p->next;
....*cp++ = c;
....next_char = *++cp;
....malloc(sizeof (struct listnode))
Type
....ratio = (float) m/n;
....p = (struct listnode *)malloc(sizeof(structlistnode));