In this article we will be going to discuss about What is an assignment Operator in C language in detail so, if you have any doubt related this operator then stay with this article and clear your doubt.
This article include following Topics:
- What is an assignment operator in C language ?
- What is shorthand assignment operator in C language ?
- Advantage of shorthand assignment operator in C language.
- Syntax of shorthand assignment operator in C language.
Assignment Operator in C
An assignment operator in C language is used to assign the value of an expression to specified variable. We have seen the usual assignment operator,'='.
For example:
int a=10;
float b=5.5;
char a=A;
In addition,C has a set of 'shorthand' assignment operator of the form
v op=exp;
where v is a variable,exp is an expression and op is a C binary arithmetic operator.The operator op= is know as shorthand assignment operator.
The assignment statement
v op=exp;
is equivalent to
v=v op(exp);
with v is evaluated only once.consider an example
a+= m+1;
This is same example as the statement
a=a+(m+1);
The shorthand operator += means 'add m+1 to a' or 'increment a by m+1'.For m=2, the above statement becomes
a+=3;
and this statement is executed,3 is added.if the old value of a is, say 5,then the new value of a statement is 8.
shorthand assignment operator has three advantages:
- What appear left-hand side need not be repeated and therefore it become easier to write.
- The statement is more concise and easier to read.
- The statement is more efficient.
Conclusion:
I have tried to cover all topic of assignment operator in C language,I hope after reading this article you have no any doubt remaining related to this topic but if you have any doubt then feel free comment below.
