Assignment Operators in C

Assignment Operators in C –

C – Assignment Operators

There are different types of operators in C programming language, such as arithmetic, relational, bitwise, assignment, etc. The assignment operator is used to assign a value, variable and function to another variable. Let us discuss different types of assignment operators like =, +=, -=, /=, *= and %=. An assignment operator is used to assign a value to a variable. The most common assignment operator is =

Read Also – C – break statement in C programming

Example 3: Assignment Operators

Table of Operators in c

OperatorExampleSame as
=a = ba = b
+=a += ba = a+b
-=a -= ba = a-b
*=a *= ba = a*b
/=a /= ba = a/b
%=a %= ba = a%b
// Working of assignment operators
#include <stdio.h>
int main()
{
    int a = 5, c;

    c = a;      // c is 5
    printf("c = %d\n", c);
    c += a;     // c is 10 
    printf("c = %d\n", c);
    c -= a;     // c is 5
    printf("c = %d\n", c);
    c *= a;     // c is 25
    printf("c = %d\n", c);
    c /= a;     // c is 5
    printf("c = %d\n", c);
    c %= a;     // c = 0
    printf("c = %d\n", c);

    return 0;
}

Output

c = 5 
c = 10 
c = 5 
c = 25 
c = 5 
c = 0
types of operators in C programming

Tag –

Assignment Operators in C

Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment