C and Java operators have the same precedence and associativity.
C has two pointer-related operators
prefix operators &
and *
that do not appear Java.
&x
is a pointer
containing the address of a variable x
.
When a
is a pointer variable, *a
is the value contained in the memory location addressed within a
.
There is a third pointer-related variable ->
that allowed
(*p).f
to be writted as p->f
.
C also have a prefix operator sizeof
that gives the size of
a variable or type in bytes.
Java has an class-related binary operator instanceof
which does not appear in C. Java also has an unsigned right shift
opeator >>>
which is not needed in C because
C allows integers to be declared as unsigned.
When expressed in binary 107 is 1101011 and 201 is 11001001.
Suppose these values are stored in unsigned char
's that
are eight bits long. What is the result of the following operators?
107 & 201
107 && 201
107 | 201
107 || 201
~ 107
! 107
107 >= 201
107 <= 201
107 >> 2
107 << 2
The formal definition of C does not define the result of shifting a negative number of places or more places than the bit-size of the shifted number. The right shifting of negative numbers is also undefined. Consequently, the following should be avoided.
5 >> -1
5 << -1
5 >> 107
5 << 107
-107 >> 2