EID2623 Operators
EID2623 Operators
Control Operations
Operators
Arithmetic Operators (+ ,- ,* ,/, %)
Bitwise Operators (&, |, ^, !)
Unary Operators (++, --)
Relational Operators
To compare the relationship between operands and bring out a
decision and program accordingly.
greater >
greater or equal >=
lesser <
lesser or equal <=
equal ==
not equal !=
Logical Operators
To compare or evaluate logical and relational expressions.
OR gate ( || )
AND gate (&&)
Arithmetic Operators
#include<stdio.h>
int main()
{
int a = 10, b = 2 , c;
c = a + b;
printf("The sum of a and b is %d\n", c);
c = a - b;
printf("The a - b is %d\n", c);
c = a * b;
printf("The a X b is %d\n", c);
c = a / b;
printf("The a / b is %d\n", c); The a b is 8
return 0;
}
The a x b is 20
The a / b is 5
Bitwise Operators
Truth Table
AND Gate (&)
OR Gate (|)
AND
OR
EX-ORGate (^)
XOR
Bitwise Operators
#include<stdio.h>
int main()
{
int a = 0xff, b = 0x07, c , d;
c = a & b;
printf("Result bitwise AND is %x\n", c);
c = a | b; 0xff
1111 1111
printf("Result bitwise OR is %x\n", c);
0000 0111
c = a ^ b; 0x07
printf("Result
bitwise
EX-OR
0xff
1111
1111
AND gate
0000
0111is %x\n", c);
c = ! (a & b);
0xff
1111
1111
0x07 bitwise
0000
0111
printf("Result
NOT
is %x\n", c);
d = b<<3; 0x07
00000111
OR
1111
0xffgate
11111111
1111
printf("Result shift to left 3 steps is %x\n", d);
Ex-OR
0x07 gate 1111
00001000
0111
return 0; 0x07
00000111
AND gate
0000 0111
00111000
Input - Friends
Process - You
Output - Friends
& gate
| gate
Not gate
ExOR
Not | gate
Condition operator
More on operations
Equals symbol = is used for assignment
Double equals symbol == is used for equality
Example:
a = b +1;
assign value to a
a = = b +1;
a != b + 1;
More on operations
Assignments of the form:
y = y+1;
increment the current value of y
It is equal to y++ ;
i.e y++ is post increment, ++y is pre increment
sum = x + y++ is not same as sum = x + ++y
Incremental operations:
if y = 4 and x = 7 determine
sum = x + (y++);
sum is 11 because 11 = 7 + 4
sum = x + (++y);
sum is 12 because 12 = 7 + 5
sum is 10 because 10 = 7 + 3
The End of
Operation