Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Assignment Operators in C Program


Assignment operators are used to assigning value to a variable.

Operator Example
= a=b
+= a+=b (a=a+b)
-= a-=b (a=a-b)
*= a*=b (a=a*b)
/= a/=b (a=a/b)
%= a-=b (a=a%b)

Example : pgm.c

#include <stdio.h>
int main()
{
    int a = 4, b;

    b = a;      // b is 4
    printf("Value of b = %d\n", b);
    b += a;     // b is 8 
    printf("Value of b = %d\n", b);
    b -= a;     // b is 4
    printf("Value of b = %d\n", b);
    b *= a;     // b is 16
    printf("Value of b = %d\n", b);
    b /= a;     // b is 4
    printf("Value of b = %d\n", b);
    b %= a;     // b = 0
    printf("Value of b = %d\n", b);

    return 0;
}

Output:

Value of b = 4
Value of b = 8
Value of b = 4
Value of b = 16
Value of b = 4
Value of b = 0