Assignment Operators in C

In all programming languages you will find assignment operators. Assignment operators are used to assign values to variables. In this tutorial I will show you the assignment operators available in C programming language.

Now, let’s see the assignment operators in C programming language:

Operator Example Equivalent
= x = 5 x = 5
+= x += 5 x = x + 5
-= x -= 5 x = x – 5
*= x *= 5 x = x * 5
/= x /= 5 x = x / 5
%= x %= 5 x = x % 5
&= x &= 15 x = x & 15
|= x |= 15 x = x | 15
^= x ^= 15 x = x ^ 15
>>= x >>= 1 x = x >> 1
<<= x <<= 1 x = x << 1

C program code with arithmetic & assignment operators:

#include<stdio.h>
void main()
{
    int a=9,b=3,c=0;

    printf("a+b=%d\n",a+b);
    printf("a-b=%d\n",a-b);
    printf("a*b=%d\n",a*b);
    printf("a/b =%d\n",a/b);
    printf("Reminder(a%b)=%d\n",a%b);
    
}

Output:

a+b=12
a-b=6
a*b=27
a/b=3
Reminder(a%b)=0

Click Operators in C to know other operators in C programming language.

In this tutorial, I have shown assignment operators in C. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment