VOOZH about

URL: https://www.geeksforgeeks.org/c/assignment-operators-in-c-c/

⇱ Assignment Operators in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Assignment Operators in C

Last Updated : 17 Oct, 2025

In C, assignment operators are used to assign values to variables. The left operand is the variable and the right operand is the value being assigned. The value on the right must match the data type of the variable otherwise, the compiler will raise an error.


Output
10

Explanation: In the above example, the assignment operator (=) is used to assign the value 10 to the variable a. The printf() function then prints the value of a, which is 10, to the console.

Compound Assignment Operators

C also provides compound assignment operators that combine an operation and assignment in a single step. They make the code shorter and more efficient.

Here are the most commonly used compound assignment operators:

1. Addition Assignment (+=)

Adds the value of the right operand to the left operand and stores the result in the left operand.


Output
a = 8

2. Subtraction Assignment (-=)

Subtracts the value of the right operand from the left operand and stores the result in the left operand.


Output
5

3. Multiplication Assignment (*=)

Multiplies the value of the right operand by the left operand and stores the result in the left operand.


Output
50

4. Division Assignment (/=)

Divides the left operand by the right operand and stores the result in the left operand.


Output
2

5. Modulus Assignment (%=)

Takes the modulus of the left operand by the right operand and stores the result in the left operand.


Output
0

6. Bitwise AND Assignment (&=)

Performs a bitwise AND operation and assigns the result.


Output
12

7. Bitwise OR Assignment (|=)

Performs a bitwise OR operation and assigns the result.


Output
a |= b: 61

8. Bitwise XOR Assignment (^=)

Performs a bitwise XOR operation and assigns the result.

9. Bitwise Left Shift Assignment (<<=)

Shifts the bits of the left operand to the left by the number of positions specified by the right operand and assigns the result.


Output
240

10. Bitwise Right Shift Assignment (>>=)

Shifts the bits of the left operand to the right by the number of positions specified by the right operand and assigns the result.


Output
15
Comment