Assignment Operators In C Programming


Assignment operators in C:

  • In C programs, values for the variables are assigned using assignment operators.
  • For example, if the value “10” is to be assigned for the variable “sum”, it can be assigned as “sum = 10;”
  • There are 2 categories of assignment operators in C language. They are,
    1. Simple assignment operator ( Example: = )
    2. Compound assignment operators ( Example: +=, -=, *=, /=, %=, &=, ^= )
sum = 10;
10 is assigned to variable sum
This is same as sum = sum + 10
This is same as sum = sum – 10
This is same as sum = sum * 10
This is same as sum = sum / 10
This is same as sum = sum % 10
This is same as sum = sum & 10
This is same as sum = sum ^ 10

Example program for C assignment operators:

  • In this program, values from 0 – 9 are summed up and total “45” is displayed as output.
  • Assignment operators such as “=” and “+=” are used in this program to assign the values and to sum up the values.


Continue on types of C operators:

Click on each operator name below for detailed description and example programs.

Arithmetic_operatorsThese are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus
Assignment_operatorsThese are used to assign the values for the variables in C programs.
These operators are used to compare the value of two variables.
These operators are used to perform logical operations on the given two variables.
These operators are used to perform bit operations on given two variables.
Conditional operators return one value if condition is true and returns another value is condition is false.
These operators are used to either increase or decrease the value of the variable by one.
&, *, sizeof( ) and ternary operators.


# include <stdio.h>
Total+=i;// This is same as Total = Toatal+i
printf("Total = %d",Total);

The latest version of this topic can be found at C Assignment Operators.

An assignment operation assigns the value of the right-hand operand to the storage location named by the left-hand operand. Therefore, the left-hand operand of an assignment operation must be a modifiable l-value. After the assignment, an assignment expression has the value of the left operand but is not an l-value.



unary-expression assignment-operator assignment-expression

assignment-operator: one of
= *=–= <<= >>= &=

The assignment operators in C can both transform and assign values in a single operation. C provides the following assignment operators:

OperatorOperation Performed
=Simple assignment
*=Multiplication assignment
Division assignment
Remainder assignment
Addition assignment
–=Subtraction assignment
<<=Left-shift assignment
>>=Right-shift assignment
&=Bitwise-AND assignment
Bitwise-exclusive-OR assignment
Bitwise-inclusive-OR assignment

In assignment, the type of the right-hand value is converted to the type of the left-hand value, and the value is stored in the left operand after the assignment has taken place. The left operand must not be an array, a function, or a constant. The specific conversion path, which depends on the two types, is outlined in detail in Type Conversions.

Assignment Operators

Categories: 1

0 Replies to “Assignment Operators In C Programming”

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *