Professional Documents
Culture Documents
Right shift operator shifts all bits towards right by certain number of specified bits.
It is denoted by >>.
Left shift operator shifts all bits towards left by a certain number of specified bits.
The bit positions that have been vacated by the left shift operator are filled with 0.
The symbol of the left shift operator is <<.
For Example:
Output:
Special Operators:
Comma Operator:
For example:
int a, c = 5, d;
The sizeof is a unary operator that returns the size of data (constants, variables,
array, structure, etc).
For Example:
Output:
Precedence of Operators:
int x = 5 - 17* 6;
b = a;
Here, the value of a is assigned to b, and not the other way around. It's because
the associativity of the = operator is from right to left.
Another Example:
1 == 2 != 3
Here, operators == and != have the same precedence. And, their associativity is
from left to right. Hence, 1 == 2 is executed first.
(1 == 2) != 3
If a statement has multiple operators, you can use parentheses () to make the
code more readable.
Arithmetic Expressions:
When both the operands are of type integer, then arithmetic will be
performed, and the result of the operation would be an integer value. For
example, 3/2 will yield 1 not 1.5 as the fractional part is ignored.
When both the operands are of type float, then arithmetic will be
performed, and the result of the operation would be a real value. For
example, 2.0/2.0 will yield 1.0, not 1.
If one operand is of type integer and another operand is of type real, then
the mixed arithmetic will be performed. In this case, the first operand is
converted into a real operand, and then arithmetic is performed to produce
the real value. For example, 6/2.0 will yield 3.0 as the first value of 6 is
converted into 6.0 and then arithmetic is performed to produce 3.0.
For Example:
Type Conversions in C:
A type cast is basically a conversion from one type to another. There are two
types of type conversion:
Done by the compiler on its own, without any external trigger from the
user.
Generally takes place when in an expression more than one data type is
present. In such condition type conversion (type promotion) takes place to
avoid loss of data.
All the data types of the variables are upgraded to the data type of the
variable with largest data type.
For Example:
Output:
Syntax:
(type) expression
For Example:
Output: