What is operator in C programming language?
Operator in C is a symbol. It will tell compiler to perform either mathematical or logical functions. Moreover, in C programming language there are many C operator programs. You will find here complete list of C operators in C with examples.
List of C arithmetic operators
| Name of the operator | Description |
| + | It will add two operands |
| / | Divides numerator by the de-numerator |
| * | Operator will multiply both operands |
| − | It will subtract second operand from first operand |
| ++ | This operator is increment operator. It will increase integer value by one |
| % | This is a modulus operator. And remainder of after integer division |
| — | It is decrement operator. It decreases integer value by one |
Program examples
Logical operators list in C programming language
| Operator’s name | Description |
| || | This is Logical OR Operator. When any two operands is non-zero. Then condition becomes true |
| ! | It is Logical NOT Operator. You can use it to reverse logical state of operand. In addition, when condition is true, then Logical NOT operator makes it false |
| && | Finally, this is Logical AND operator. In case, both operands are non-zero. Then condition will become true |
Example programs
Relational operators in C language
| Operator’s name | Description |
| != | It checks values of two operands are equal or not. When values are not equal. Then condition becomes true |
| == | Checks values of two operands are equal or not. When yes, then condition will become true |
| < | Checks value of left operand is less than value of right operand. And if yes. Then condition will be true |
| > | Checks value of left operand is greater than value of right operand. In case yes, then condition will be true |
| >= | This operator will check value of left operand is greater than or equal to value of right operand. Moreover, if yes, then condition changes to true |
| <= | It will check value of left operand is less than or equal to value of right operand. Furthermore, if yes, then condition will be true |
Example programs
List of C language bitwise operators
| Name of the operator | Description |
| | | This is Binary OR Operator. It copies bit if it is there in either operand |
| & | Binary AND Operator will copy bit to result if there in both operands |
| << | It is Binary Left Shift Operator. Here, left operands value moves left by
number of bits. Moreover, right operand specifies bits
|
| >> | Binary Right Shift Operator. Here, left operands value moves right by number of bits. Again right operand will specify bits |
| ^ | Binary XOR Operator will copy bit when it is set in one operand only |
| ~ | Finally, this is Binary Ones Complement Operator. It is unary. Additionally, it has effect of flipping bits |
Example programs
List of Misc Operators – sizeof & ternary operators in C
| Operator’s name | Description |
| ? : | It is conditional expression |
| sizeof() | It will return size of variable |
| * | It will point to variable |
| & | & returns address of variable |
Program examples
Assignment operators of C language
| Operator | Description of the operator |
| = | Simple assignment operator will assign values from right side operand to left side operand |
| -= | This is Subtract AND assignment operator. It will subtract right operand from left operand. Moreover, it assigns result to left operand. |
| += | Add AND assignment operator. It will add right operand to left operand. Moreover, assigning result to left operand is its responsibility |
| %= | This is Modulus AND assignment operator. In addition, it will take modulus using two operands. In addition, it assigns result to left operand |
| *= | Multiply AND assignment operator multiplies right operand with left operand. It will also assign result to left operand |
| /= | Divide AND assignment operator divides left operand with right operand. In addition, it will assign result to left operand |
| &= | It is Bitwise AND assignment operator |
| <<= | This operator is Left shift AND assignment |
| >>= | It is Right shift AND assignment operator |
| |= | Bitwise inclusive OR and assignment operator |
| ^= | Finally, this operator is Bitwise exclusive OR and assignment |
Example programs
C operators precedence and associativity
An operator precedence will decide grouping of terms in expressions. It will also decide how to evaluate expressions. However, you must remember that few C operators will have more precedence than the others.
You can check below list. Because here you will know C operators precedence and associativity. In addition, table has highest precedence operator first. In addition, the list will go from higher to lower precedence. You may even look at C operators associativity.
List of C operators precedence and associativity in C programming language
| Name of the category | Associativity | Operator |
| Postfix | Left to right | () [] -> . ++ – – |
| Unary | Right to left | + – ! ~ ++ – – (type)* & sizeof |
| Multiplicative | Left to right | * / % |
| Additive | Left to right | + – |
| Shift | Left to right | << >> |
| Relational | Left to right | < <= > >= |
| Equality | Left to right | == != |
| Bitwise AND | Left to right | & |
| Bitwise XOR | Left to right | ^ |
| Bitwise OR | Left to right | | |
| Logical AND | Left to right | && |
| Logical OR | Left to right | || |
| Conditional | Right to left | ?: |
| Assignment | Right to left | = += -= *= /= %=>>= <<= &= ^= |= |
| Comma | Left to right | , |
Program examples
So now you know C operators programs examples. Practise C operators in C and C operators precedence. This will help you with C functions chapter.
No comments:
Post a Comment