Binary operators of C are the same as in other programming languages. These are + (add), - (subtract), * (multiply), / (divide) and %(modulo). The parentheses() are used to clarify complex operations.
Apart from the modulo operator(%), you will be familiar with the other operators. The modulo operator gives the remainder of the divisio between two integer values. For instance,
int x, y, z;
x=27;
y=x%5;
z=x/5;
y will be set to 2. Aslo note that z will take on the value 5.
C also provides a facility to convert variables to a specific type before being evaluated in an expression, through the type casting facility. This has been used in the following code:
int i,j;
double d;
d=i/j;
The problem with the above assignment is that the fractional portion of the above division is lost and d is effectively assigned the quotient of the division of the two integers.
0 comments:
Post a Comment