Assignment Operators
Assignment Operators
They are used to assign the result of an expression to a variable.
Syntax
identifier = Expression
There are five assignment operators. They are,
a=a+1 a+=1
a=a- 1 a-= 1
a=a*2 a*=2
a=a/2 a/= 2
a=a%2 a%=2
Advantages:
- Left-hand side operator need not repeated.
- Easy to Read
- More Efficient
Example For C assignment operator
#include <stdio.h>
// C assignment operator Example Program
void main(){
int a = 10;
// = Operator
int b = a;
printf("b = %d\n",b);
// += Operator
b += 10;
printf("b += 10;b = %d\n",b);
// -= Operator
b -=5;
printf("b -=5;b = %d\n",b);
// *= Operator
b *=4;
printf("b *=4;b = %d\n",b);
// /= Operator
b /=2;
printf("b /=2;b = %d\n",b);
}
Sample Output:
b = 10
b += 10;b = 20
b -=5;b = 15
b *=4;b = 60
b /=2;b = 30
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- File Management
- C Identifiers
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )