Professional Documents
Culture Documents
Produces remainder of
the integer division
Can’t be used in
floating point data
float x=14,y=4;
x+y 18.0000000
x-y 10.0000000
x*y 56.0000000 Modulo Division
x/y 3.5 (Gives
Fractional part)
x%y NOT VALID for real
1. ARITHMETIC OPERATORS
Use %f for
Mixed-mode Arithmetic
printing
operands are real and integer Division
Expression: mixed-mode expression
Operation: mixed-mode arithmetic
3
1
4
2. RELATIONAL OPERATORS
2. RELATIONAL OPERATORS
3. LOGICAL OPERATORS
Compare more than one condition
False
exp1 is
evaluated
first
True
6. INCREMENT & DECREMENT OPERATOR
Add 1 Subtract 1
m=m+1
m =m-1
m = 5; m = 5;
y = m++; /* POSTFIX */ y = ++m; /* PREFIX */
int j = 7, m=5, a;
a = j + m++ + 2 a = j + ++m + 2
a = 14, m = 6 a = 15 , m = 6
a = j + m-- + 2 a = j + --m + 2
a = 14 , m = 4 a = 13 , m = 4
POSTFIX PREFIX
1. Evaluate the expression 1. Increment/ Decrement variable
2. Increment/ Decrement variable 2. Evaluate the expression
7. BITWISE OPERATOR
Use: To manipulate data at bit level
Can not be used with float and double, Use with int only
8. SPECIAL OPERATOR
Comma Operator
• Use to link related expressions
• Evaluated from left to right
1.
3. t = x , x = y , y = t ;
8. SPECIAL OPERATOR
sizeof operator : compile time operator
• Syntax : sizeof ( operand )
• Returns number of bytes occupied by operands
ARITHMETIC EXPRESSION
Expression: Combination of operators and operands
a = x + y * 10;
Expressions: Evaluated using an assignment statement of the form
variable = expression;
PRECEDENCE OF ARITHMETIC OPERATORS
Arithmetic Expression without parenthesis will be evaluated
from left to right
using the rule of precedence of operators.
a = x + y * 10;
TWO left to right passes through expression
• 9 – (12 / (3 + 3) * 2) - 1 = 4
• Nested parentheses
• 9 – ( (12 / 3) + 3 * 2) - 1 = -2 • Innermost evaluated first
CHAPTER 3 29
MATHEMATICAL FUNCTIONS
• #include<math.h>
• gcc prog1.c -lm