An operator is a symbol that instruct the compiler to perform specific mathematical or logical operation. C language has following type of operators:
• Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators • Misc Operators This post will explain the arithmetic, relational, logical, bitwise, assignment and other operators. Arithmetic Operators:The table below shows all the arithmetic operators supported by C language. Let suppose the value of A is 10 and variable B is 20 then:
Relational Operators:The table shows all the relational operators supported by C language. Let suppose the value of A is 10 and variable B is 20, then:
Following table shows all the logical operators supported by C language.Let suppose the value of A is 1 and variable B has value 0, then: |
Logical Operators |
Bitwise Operators:
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ are as follows:Assume if A = 60; and B = 13; now in binary format they will be as follows:
BitWise Operators |
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
The Bitwise operators supported by C language are listed in the following table.Let suppose the value of A is 60 and variable B is 13, then:
BitWise Operators |
Assignment Operators:
following are the assignment operators supported by C language:assignment operators |
Misc Operators ↦ sizeof & ternary
following are few other important operators including sizeof and ? : supported by C Language.Misc Operators |
Operators Precedence in C:
Operator precedence determines priority of operators in an expression . It also determines how expression is evaluated. Some of the operators have higher precedence than others; for an instance , the multiplication operator has higher precedence than the addition operator.For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
The operators with the highest precedence is at the top of the table, those with the lowest are at the bottom. In an expression, higher precedence operators will be evaluated first.
Operators Precedence in C: |
0 comments:
Post a Comment