## C OperatorsAn operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc. There are following types of operators to perform different types of operations in C language. - Arithmetic Operators
- Relational Operators
- Shift Operators
- Logical Operators
- Bitwise Operators
- Ternary or Conditional Operators
- Assignment Operator
- Misc Operator
## Precedence of Operators in CThe precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operator direction to be evaluated; it may be left to right or right to left. Let's understand the precedence by the example given below: The value variable will contain The precedence and associativity of C operators is given below:
## Arithmetic Operators:
operations. The arithmetic operators in C are as follows:fundamental mathematical
It has the following syntax:
result = 8
.subtraction operator
It has the following syntax:
result = 5
It has the following syntax:
result = 20
It has the following syntax:
result = 5
It has the following syntax:
result = 1 ## Relational Operators:
or true (1). The relational operators in C are as follows:false (0)
It has the following syntax:
result=1 (true)
or equal.not
It has the following syntax:
result=1 (true)
It has the following syntax:
result=1 (true)
It has the following syntax:
result=1 (true)
It has the following syntax:
result=1 (true)
It has the following syntax:
result=1 (true) ## Shift Operators:A binary number's bits can be moved to the using right. The C shift workers are listed below:shift operators
It has the following syntax:
result = 20 // 0001 0100 in binary
by the number of positions specified by the second operand.right
It has the following syntax:
result = 5 // 0000 0101 in binary ## Logical Operators:
and return either boolean values or true (1) Here are the logical operators in C:false (0).
if both operands are true.true
It has the following syntax:
result = 1 (true)
if at least one of the operands is true.true
It has the following syntax:
result = 1 (true)
It has the following syntax:
result = 0 (false) ## Bitwise Operators:
of the operands. Here are the bitwise operators in C:bits
It has the following syntax:
result = 1 // 0000 0001 in binary
It has the following syntax:
result = 7 // 0000 0111 in binary
It has the following syntax:
result = 6 // 0000 0110 in binary
It has the following syntax:
result = -6 // 1111 1001 in binary (assuming 8-bit representation)
a value based on a condition.assign
It has the following syntax:
result = 5 ## Assignment Operator:
side operands to the right.left side operands
It has the following syntax:
No output. The value 5 is assigned to variable 'a'. ## Miscellaneous Operator:The fall under the comma operator.miscellaneous operator category
, of a bytes or a variable.data type
It has the following syntax:
size = 4 // Assuming int occupies 4 bytes
.last expression
It has the following syntax:
result = 15 // a = 7, b = 6, a + b = 13 ## Uses of Operators:The following are some common uses for the various kinds of operators in C: - Calculations in
are performed using the addition and subtraction operators*fundamental mathematics*.*(+ and -)* - If the user wants to do some
and*multiplication*operations, utilize the multiplication and division operators*division*.*(* and /)* - The remainder of a
is obtained using the*division operation*.*modulus operator (%)* and*Equality*are needed to compare values and determine whether they are equal or not.*inequality operators (== and!=)*- Use the
and*greater than*operators*less than*to compare values and determine if one value is*(>and <)*or*larger than**less than* - A value's relationship to another value may be determined using the
*larger than or equal to*.*and less than or equal to operators (>= and <=)* - A binary number's bits are shifted to the
using the*left*.*left shift operator (<<)* - A binary number's bits can be shifted to the
using the*right*.*right shift operator (>>)* - Use the
to combine many criteria and determine if each condition is*logical AND operator (&&)*.*true* - When combining several criteria, the
is used to determine if at*logical OR operator (||)*of the conditions is*least one*.*true* - The
is used to*logical NOT operator (!)*a condition's value.*negate* - When two numbers' individual bits are involved, the
is utilized to accomplish the action.*bitwise AND operator (&)* - The
is employed when two numbers' individual bits are involved.*bitwise OR operator (|)* *Bitwise exclusive OR*is performed on individual bits of two integers using the*operator*.*bitwise XOR operator ()*- Use the
to*bitwise NOT operator ()*or*flip*the bits of an integer.*invert* - Use the
to assign a value depending on a condition in a compact form.*ternary operator (?:)* - A value is assigned to a
using the*variable*.*simple assignment operator (=)* - The
is used to calculate a variable's or*sizeof operator*in bytes.*data type's size* - When evaluating several expressions, the
returns the result of the last expression that was evaluated.*comma operator (,)*
## Conclusion:In this blog, we have covered the several types of C operators, such as , and what results to expect. By becoming proficient with these operators, you may effectively handle data and write reliable C programs.features, syntax, samplesNext TopicComments in C |