2. Operators
• Operators are the special symbols that work
on operand. Like in a + b, a and b are
operands and + is special symbol (operator)
which is working or operating on them.
way2ITech
4. Assignment Operator
• Used to assign value to variable. = is
assignment operator.
• NOTE: Value at right side is assigned to left
side variable.
int a = 10;
int b = 55;
b = a;
Value of b will become 10 and value of a will
remain as such. way2ITech
5. Lvalues and Rvalues
• lvalue : An expression that is an lvalue may
appear as either the left-hand or right-hand
side of an assignment.
way2ITech
6. • rvalue : An expression that is an rvalue may appear
on the right- but not left-hand side of an assignment.
• Variables are lvalues and so may appear on the left-
hand side of an assignment. Numeric literals are
rvalues and so may not be assigned and can not
appear on the left-hand side.
• Following is a valid statement:
int g = 20;
• But following is not a valid statement and would
generate compile-time error:
• 10 = 20;
way2ITech
9. Priority of operators
• If 2 operators with same priority come?, then
we will follow left to right rule. Means from
left, which operator comes first, will be
executed. way2ITech
17. Unary Operators
• These are called as Unary operators as there is
one operator and one operand only. It is two
types:
way2ITech
18. Rule to solve
• 1. Solve Pre
• 2. Solve Equation (ignore all pre and post and
solve as normal equation)
• 3. Solve Post
way2ITech
19. Comparison Operators
• They are used to compare value of 2 variables
• These operators deal in true or false. They
return 0 if false and 1 (non zero number) for
true.
way2ITech
20. • NOTE:
There is difference in x = y and x == y.
x=y assigns value of variable y to variable x.
way2ITech
21. Logical Operators
• They are used to combine two or multiple
conditions.
• 1. And &&
• 2. OR ||
• 3. NOT !
way2ITech
22. && and || are useful in the following programming
situations:
I. When it is to be tested whether a value falls within a
particular range or not.
II. When after testing several conditions the outcome is
only one of the two answers (This problem is often
called yes/no problem or combine multiple
conditions).
• These also work in Boolean Values (True/False).
way2ITech
23. • Following table shows all the logical operators.
Assume variable A holds 1 and variable B
holds 0, then:
way2ITech
24. Bitwise Operator
• This work in bits but takes input and gives
Output in decimal form only.
way2ITech
27. Arithmetic shift
• The two basic types are the
• arithmetic left shift (<<)
• arithmetic right shift (>>)
• For binary numbers it is a bitwise operation that
shifts all of the bits of its operand; every bit in the
operand is simply moved a given number of bit
positions, and the vacant bit-positions are filled in.
• 23<<1 means shift bits of 23 by 1. Sly, 23>>1 means
shift bits of 23 by 1.
way2ITech
30. sizeof() operator
• This is used to get size in bytes for datatype,
variable, structures, and union. It returns the
size in bytes.
• sizeof(int) -> 2 (in blue screen TC)
• sizeof(char) -> 1
• sizeof(float) -> 4
way2ITech