Lecture 7 8 (Pic) .PDF 10
Lecture 7 8 (Pic) .PDF 10
Lecture 7 8 (Pic) .PDF 10
Simple
assignment = sum = 10
10 is assigned to
operator variable sum
sum += 10 This is same as
Compound += sum = sum + 10
assignment This is same as
operators -= sum -= 10 sum = sum – 10
This is same as
*= sum *= 10 sum = sum * 10
This is same as
/+ sum /= 10 sum = sum / 10
This is same as
%= sum = sum % 10
sum %= 10
This is same as
&= sum&=10 sum = sum & 10
This is same as
^= sum ^= 10 sum = sum ^ 10
Relational operators are used to find the relation between two
variables. i.e. to compare the values of two variables in a C
program.
S.no Operators Example Description
x is greater than y
1 > x>y
x is not equal to y
6 != x != y
These operators are used to perform logical operations
on the given expressions.
There are 3 logical operators in C language. They are,
logical AND (&&), logical OR (||) and logical NOT (!).
S.no Operators Name Example Description
Operator_symbol Operator_name
& Bitwise_AND
| Bitwise OR
~ Bitwise_NOT
^ XOR
<< Left Shift
>> Right Shift
x y x|y x&y x^ y
0 0 0 0 0
0 1 1 0 1
1 0 1 0 1
1 1 1 1 0
Conditional operators return one value if condition is true and
returns another value is condition is false.
This operator is also called as ternary operator.
Syntax : (Condition? true_value:false_value);
Example: (A > 100 ? 0 :1);
In above example, if A is greater than 100, 0 is returned else 1 is
returned. This is equal to if else conditional statements.
Increment operators are used to increase the value of the variable
by one and decrement operators are used to decrease the value of
the variable by one in Cprograms.
Syntax:
Increment operator: ++var_name ;( or) var_name++;
Decrement operator: – -var_name; (or) var_name – -;
Example:
Increment operator : ++i; i ++ ;
Decrement operator : – – i ; i – – ;
Below table will explain the difference between pre/post increment
and decrement operators in C.
1 Pre increment
++i Value of i is incremented before assigning it to
variable i.
Example : * awhere, * is
pointer to the variablea.
This gives the size of the
3 Sizeof () variable.
Symbols Meaning