☜
☞
Operators
Operators are special symbols in programming languages that perform specific operations on one or more operands (values or variables). In the C programming language, there are several types of operators, including:
- Arithmetic operators: Perform basic arithmetic operations such as addition, subtraction, multiplication, and division. For example:
int a = 10;
int b = 5;
int c = a + b; // c is 15
int d = a - b; // d is 5
int e = a * b; // e is 50
int f = a / b; // f is 2
- Assignment operators: Assign a value to a variable. For example:
int a = 10;
int b = 5;
a = b; // a is now 5
- Comparison operators: Compare two values and return a Boolean value indicating whether the comparison is true or false. For example:
int a = 10;
int b = 5;
if (a > b) {
printf("a is greater than b\n");
}
if (a == b) {
printf("a is equal to b\n");
}
if (a < b) {
printf("a is less than b\n");
}
- Logical operators: Perform logical operations such as AND, OR, and NOT. For example:
int a = 1;
int b = 0;
if (a && b) {
printf("Both a and b are true\n");
} else {
printf("Either a or b is false\n");
}
if (a || b) {
printf("Either a or b is true\n");
} else {
printf("Both a and b are false\n");
}
if (!a) {
printf("a is false\n");
} else {
printf("a is true\n");
}
- Increment and decrement operators: Increase or decrease the value of a variable by 1. For example:
int a = 10;
a++; // a is now 11
a--; // a is now 10
There are many other types of operators in C, each serving a specific purpose. It's important to understand how these operators work and how to use them effectively in your programs.
☜
☞