Assignment Operators in C

In this video tutorial we show Compound Assignment Operators in C programming language.

Related Read:
Simple Calculator Application In C

Assignment Operators

If a and c are the operands.

c += a; is equal to writing c = c + a;
c -= a; is equal to writing c = c – a;
c *= a; is equal to writing c = c * a;
c /= a; is equal to writing c = c / a;
c %= a; is equal to writing c = c % a;

Assignment Operator +=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c += a ; // c = c + a;

    printf("%d\n\n", c);

    return 0;
}

Output:
50

Assignment Operator -=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c -= a ; // c = c - a;

    printf("%d\n\n", c);

    return 0;
}

Output:
10

Assignment Operator *=

 
#include < stdio.h >

int main()
{
    int a = 20, c = 30;

    c *= a ; // c = c * a;

    printf("%d\n\n", c);

    return 0;
}

Output:
600

Assignment Operator /=

 
#include < stdio.h >

int main()
{
    int a = 2, c = 20;

    c /= a ; // c = c / a;

    printf("%d\n\n", c);

    return 0;
}

Output:
10

Assignment Operator %=

 
#include < stdio.h >

int main()
{
    int a = 2, c = 20;

    c %= a ; // c = c % a;

    printf("%d\n\n", c);

    return 0;
}

Output:
0

Compound Assignment Operators in C Programming Language


[youtube https://www.youtube.com/watch?v=-_ZBdT2Yxqo]

YouTube Link: https://www.youtube.com/watch?v=-_ZBdT2Yxqo [Watch the Video In Full Screen.]


You can also learn about Logical and Relational Operators in C:
Relational Operators In C
Logical Operators In C

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert