![]() |
| Operators in C language |
Upon completing this series of article,you will be able to know:
- The various built-in operators of C language.
- Identify bitwise and special operators.
- Discuss how operator precedence and associativity rules are applied.
- Determine how arithmetic expression are evaluated.
- Discuss how operator precedence and associativity rules are applied.
Operator in C:
An operator is symbol that tells the compiler to perform certain mathematical or logical manipulation. An Operators are used in program to transfer data variables.They usually form a part of the Mathematical or logical expression.
C operators may be classified into number of categories.They include:
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Assignment Operator
- Increment and Decrement Operator
- Conditional Operator
- Bitwise Operator
- Special Operator
Expression in C:
An expression is sequence of operands and operators that reduces to a single value.For example,
10+15 is an expression whose value is 25.The value are often the other than void.
Operands:- Like in above expression 10,15 are as operand.
Operators:- + is behave as a operator.
Note:- During this article,I will be going to discuss only basics of operators like its definition and Symbols and if you want to learn about each operators in detail then link is given in the bottom of this article.
Arithmetic Operator in C:
C provide all the fundamental arithmetic operator with the help of which a programmer can perform all the arithmetic operation like addition(+),subtraction(-),multiplication(*),division(/) and modulo(%).
Example:-
main void()
{
int a=5,b=1,c;
c=a+b;
printf("\n %d",c);
c=a-b;
printf("\n %d",c);
c=a*b;
printf("\n %d",c);
c=a/b;
printf("\n %d",c);
c=a%b;
printf("\n %d",c);
}
Relational Operator in C:-
A relational operator is nothing but,it is an operator which is used to compare two quantities and depending on their relation,take certain decision.For example:we may compare the age of two persons,or price of two items and so on.These comparison can be done with help of relational operators.
C language supports six relational operators such as:
- < (is less than)
- <= (is less than equal to)
- > (is greater than)
- >= (is greater than equal to)
- == (is equal to)
- != (is not equal to)
Logical Operators in C:-
In addition to the relational operator,C has the following the logical operators
&& meaning logical AND
|| meaning logical OR
! meaning logical NOT
The logical operator && and ||,are used when we want to test more than one condition to make decision an example is:
a>b && x==10
Assignment Operator in C:-
Assignment operators are used in c language to assign the result of an expression to a variable.We have seen the usual assignment operator '='.
For Example:
void main()
{
int a;
a=10;
}
Increment and Decrement Operator in C:-
C allow two very useful operator not generally found in other languages.These are the increment and decrement operator:
++ and --
The operator ++ add 1 to the operand,while -- subtract 1.Both are the binary operators.
This operator are classified into two categories:-
- Pre-increment and Post increment
- Pre decrement and Post decrement
For Example:
m=5;
y=m++;
y=++m;
Similarly,
m=5;
y=m--;
y=--m;
In both cases 'y' have different value, we will discuss this operator in detail in next article.
Conditional Operator in C:-
A ternary operator pair "? :" is available in C construct conditional expression of the form:
expression1 ? expression2 : expression3
The operators "? :" work as follow: expression1 is evaluated first.if it is non zero(true). then the expression2 evaluated and becomes the value of the expression.If expression1 is false, expression3 is evaluated and it value becomes the value of the expression.
For example:
a=10;
b=15;
x=(a>b)? a:b;
Bitwise Operators in C:-
C has a distinction of supporting special operators know as bitwise operators for manipulation of data at bit level.These operator are used for testing the bits,or shifting them right or left.Bitwise operator may not be applied to float or double.
For example:- 8>>2 etc
Special Operators in C:-
C supports some special operators of interest such as comma operators,sizeof operator,pointer operators(& and *) and member selection operators(. and ->).
We will discuss all special operator in details in next article.
Conclusion in C:-
In this article we have leaned about operators in C language,types of operators in C language and expression, i hope you understand but if you have any queries related to this article then feel free comment below.
