0
C Advanced Operators
There are some advanced operators in C. First set of these operators is the Assignment Operators. Here are five operators presented in the arithmetic assignment operators:
- += (Plus Equals)
- -= (Minus Equals)
- *= (Multiply Equals)
- /= (Divide by Equals)
- %= (Modular Equals)
For example, x += y – 3 is the same as x = x + y – 3.
Other assignment operators that are not commonly used are:
- &&= (And Equals)
- ||= (Or Equals)
- &= (Bitwise And Equals)
- |= (Bitwise Or Equals)
- ^= (Bitwise Not Equals)
- >>= (Bitwise Shift Right Equals)
- <<= (Bitwise Shift Left Equals)
Here is the sample code for the arithmetic assignment operators:
/*
*
* assignment.c
*
* Program to demonstrate the use of assignment operators
*
* by Mark Virtue, 2001.
*
*/
#include <stdio.h>
main() {
int x, y;
y = 3;
x = 100;
x /= y - 1;Â Â Â // It's the same as x = x / (y - 1), therefore it can substitute to x = 100 / (3 - 1).
printf("x = %dn", x);Â Â Â // The answer is x = 50.
fflush(stdin);
getchar();
}