C Operators PDF
C Operators PDF
-----------------------
40 keywords
eg:
int
float
for
break
if
else
2) variable :
data type
1) 31 character length
2) int rollno;
int roll_no;
3) case-senstive
int rollno;
Rollno = 20; // error
4) int x1,x2,x3;
3) Operators:
1) Arithmetic Operator
+ , - , * , / , %(modulus)
2) Assignment Operator
3) Increment or decrement
(++) or (--)
int x=10;
x=11;
x=11
4) Relational Operator
x=13, y=5
x > y - true
x!=y
x=10 , y=10
x == y true
x=y
5) Logical Operator
&& - AND
|| - OR
! - Not
true = 1
false means 0
A | B | Output(A&&B)
-----------------------
0 0 0
0 1 0
1 0 0
1 1 1
( x>y || x<z )
OR
A | B | Output(A||B)
-----------------------
0 0 0
0 1 1
1 0 1
1 1 1
NOT
0 --> 1
1 --> 0
6) Bitwise Operator
| - " Or
^ - " XOR
<< - " left shift
~ - negation
int b1 = 4 , b2 = 5, b;
Bitwise AND -
b = b1 & b2;
b1 - 0100 - 4
b2 - 0101 - 5
-----------------------
b= 0100 - 4
Bitwise OR -
b = b1 | b2;
b1 - 0100 - 4
b2 - 0101 - 5
-----------------------
b= 0101 - 5
Bitwise XOR -
b = b1 ^ b2;
b1 - 0100 - 4
b2 - 0101 - 5
-----------------------
b= 0001 - 1
truth table of XOR
A | B | Output(A^B)
-----------------------
0 0 0
0 1 1
1 0 1
1 1 0
Compliment ~ :-
b = ~b1 - ~4
~ 0100
----------------
1011 - 11
-16
- ------
-5 final result
b = ~23
168421
~10111 -
------------
01000 - 8
-32
-----------------
-24
7 ) Conditional Operator or Ternary Operator
(condiation)?expression 1 : expression 2;