ASSIGNMENT OPERATORS
In C, the
assignment operator is used to assign a value to a variable. It is denoted by
the equals sign (=). The assignment operator assigns the value on the
right-hand side to the variable on the left-hand side. Here's an example:
int x; // Declare a variable named x
x = 5; // Assign the value 5 to x using the assignment operator
In this example, the value 5 is assigned to the variable `x` using the assignment operator. After the assignment, the variable `x` will hold the value 5.
The
assignment operator can also be combined with other operators to perform
compound assignments. Here are some examples of compound assignments:
int x = 10;
x += 5; // Equivalent to x = x + 5
x -= 3; // Equivalent to x = x - 3
x *= 2; // Equivalent to x = x * 2
x /= 4; // Equivalent to x = x / 4
In these examples, the compound assignment operators (+=, -=, *=, /=) combine the arithmetic operation with the assignment operation. They perform the specified arithmetic operation and assign the result back to the variable.
It's
important to note that the assignment operator works from right to left. The
expression on the right-hand side is evaluated first, and then the resulting
value is assigned to the variable on the left-hand side.