What is Operator in C-Programming Language?
![]() |
Operators in c |
An operator is a symbol that operates on a variable or value. It is used for performing certain operations like arithmetical, logical, relational, etc.
When a programmer wants to perform some types of mathematical operations then they have to use operators. The purpose of operators is mainly for mathematical and logical calculations.
Types of Operators:
In C-Programming Language there are various types of operators available to perform various operations.
Following are the list of operators present in c-programming language:-
1.Arithmetic operator : - (+,-,*,/,%).
The purpose of these operators is to perform mathematical operations like addition, subtraction, multiplication, division, modulus, etc.
2.Increment/Decrement Operators :- (++,--).
These are mainly used for incrementing and decrementing the value of an integer. '++' will increase the value by adding 1, and '--' will decrease the value by subtracting 1.
3.Assignment Operators :- (=,+=,-+,*=,/=,%=).
The purpose of these operators is to assign value to a variable. The most used operator is '='.
4.Relational Operators :- (==,<,>,>=,<=,!=).
5.Logical Operators :-(&&,||,!).
Logical operators is mainly used for decision making. A logical operator returns either 1 or 0 depends on condition is true or false.
6.Conditional Operator :- (?).
Also known as ternary operator. The main purpose of conditional operator is in decision making statements.
Syntax:
Expression1 ? statement1 : statement2;
if the expression1 is true then statement1 will get executed, else statement2 will get executed.
7.Bitwise Operators :- (<<,>>,~,&,^,|).
8.Misc Operators :- (sizeof,&,*,?:).
Precedence :
Operator precedence determines which operator is evaluated first when an expression has more then one operators.
Example :
a = 40 - 2 * 10
Here, 'a' will be assigned 20 because it is evaluated as 40-(2*10).
Because multiplication(*) has higher precedence then subtraction(-).
Associativity :
a = 5 + 2 / 10
Precedence and associativity table :
Precedence | Associativity |
---|---|
*, /, % |
Left to right |
+, - |
Left to right |
==, != |
Left to right |
<<, >> |
Left to right |
<, >, <=, >= |
Left to right |
& |
Left to right |
=, *=, +=, -=, /=, %= |
Right to left |
&=, ^=, |=, <<=, >>= |
Right to left |
, |
Left to right |
?: |
Right to left |
|| |
Left to right |
&& |
Left to right |
| |
Left to right |
(), [], ->, . |
Left to right |
0 Comments
Post a Comment