0% found this document useful (0 votes)
105 views2 pages

Operators in C

The document discusses various types of operators supported in the C language including arithmetic, relational, logical, bitwise, assignment, conditional, and special operators. It provides examples of common operators like addition, subtraction, logical AND, assignment, and describes how they are used to manipulate variables and perform operations at both the value and bit level. Key operator types are arithmetic operators for math operations, relational for comparisons, logical for true/false evaluations, bitwise for bit manipulation, and assignment for storing values.

Uploaded by

VijayGogula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views2 pages

Operators in C

The document discusses various types of operators supported in the C language including arithmetic, relational, logical, bitwise, assignment, conditional, and special operators. It provides examples of common operators like addition, subtraction, logical AND, assignment, and describes how they are used to manipulate variables and perform operations at both the value and bit level. Key operator types are arithmetic operators for math operations, relational for comparisons, logical for true/false evaluations, bitwise for bit manipulation, and assignment for storing values.

Uploaded by

VijayGogula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Operator Description

Operators in C == Check if two operand are equal


!= Check if two operand are not equal.
Language Check if operand on the left is
>
C language supports a rich set of built-in greater than operand on the right
Check operand on the left is smaller
operators. An operator is a symbol that tells the <
than right operand
compiler to perform certain mathematical or
check left operand is greater than or
logical manipulations. Operators are used in >=
equal to right operand
program to manipulate data and variables. Check if operand on left is smaller
<=
than or equal to right operand
C operators can be classified into following types,
Logical operators
Arithmetic operators
C language supports following 3 logical
Relation operators operators. Suppose a=1 and b=0,

Operator Description Example


Logical operators
&& Logical AND (a && b) is false
|| Logical OR (a || b) is true
Bitwise operators
! Logical NOT (!a) is false

Assignment operators Bitwise operators

Conditional operators Bitwise operators perform manipulations of data


at bit level. These operators also
Special operators perform shifting of bits from right to left. Bitwise
operators are not applied to float or double.
Arithmetic operators
Operator Description
C supports all the basic arithmetic operators. The & Bitwise AND
following table shows all the basic arithmetic | Bitwise OR
^ Bitwise exclusive OR
operators.
<< left shift
Operator Description >> right shift
+ adds two operands Now lets see truth table for bitwise &, | and ^
- subtract second operands from first
* multiply two operand a b a&b a|b a^b
/ divide numerator by denumerator 0 0 0 0 0
% remainder of division 0 1 0 1 1
Increment operator increases integer 1 0 0 1 1
++
value by one 1 1 1 1 0
Decrement operator decreases The bitwise shift operators shifts the bit value.
--
integer value by one The left operand specifies the value to be shifted

Relation operators and the right operand specifies the number of


positions that the bits in the value are to be
The following table shows all relation operators
shifted. Both operands have the same
supported by C.
precedence.
address of an address of the
variable variable x
Assignment Operators *x ; will be
Pointer to a
* pointer to a
Assignment operators supported by C language variable
variable x
are as follows.

Operator Description Example


assigns values from
= right side operands to a=b
left side operand
adds right operand to
a+=b is same
+= the left operand and
as a=a+b
assign the result to left
subtracts right operand
from the left operand a-=b is same
-=
and assign the result to as a=a-b
left operand
mutiply left operand
with the right operand a*=b is same
*=
and assign the result to as a=a*b
left operand
divides left operand
with the right operand a/=b is same
/=
and assign the result to as a=a/b
left operand
calculate modulus using
a%=b is
two operands and
%= same as a=a
assign the result to left
%b
operand

Conditional operator
It is also known as ternary operator and used to
evaluate conditional expression.

epr1 ? expr2 : expr3

If epr1 Condition is true ? Then value expr2 :


Otherwise value expr3

Special operator
Operator Description Example
sizeof(x) return
Returns the size of
sizeof size of the
an variable
variable x
& Returns the &x ; return

You might also like