Assignment Operator

In the previous chapter we learnt about Arithmetic operators. In this chapter we are going to learn about Assignment Operator.

Assignment operator:

Assignment Operator

An assignment operator in C is the operator which is used to assign the value to the variable. ‘=’ is basically known as assignment operator.

Example:
int x=5;

Explanation:
In left side of assignment  operator or equal to operator, there must be variable as we discussed earlier variable are used for storing data or values. So, “X” is variable which holds the value 5, “=” is an operator and “5” is constant.

Note: In right side of assignment operator there may be another variable, constant or expressions.

Some more examples:

if we have to assign a same value to different variables then we can perform this task by using assignment operator
example:

as in the above example (i.e. x=x+y) the variable x is used twice.If we don’t want to write it two times or more we can write it as shown below:

this type of assignment operator(+=) is known as compound assignment operator.

Click here for more similar concepts.
Output:

One thought on “Assignment Operator”

Leave a Reply