Show List
Control Structures
In C, an operator is a symbol that tells the compiler to perform a specific mathematical or logical operation. C provides a wide range of operators that allow you to manipulate variables, perform arithmetic calculations, and make decisions based on the values of variables.
Here are some of the most common types of operators in C:
- Arithmetic Operators: +, -, *, /, %, ++, -- Example:
lessCopy code
int a = 10, b = 20, c;
c = a + b; // c = 30
c = a - b; // c = -10
c = a * b; // c = 200
c = a / b; // c = 0
c = b % a; // c = 0
- Relational Operators: <, >, <=, >=, ==, != Example:
cssCopy code
int a = 10, b = 20;
if (a < b) {
// this block of code will be executed
}
- Logical Operators: &&, ||, ! Example:
cssCopy code
int a = 10, b = 20;
if (a > 5 && b < 25) {
// this block of code will be executed
}
- Assignment Operators: =, +=, -=, *=, /=, %= Example:
cssCopy code
int a = 10;
a += 5; // a = a + 5 = 15
a -= 5; // a = a - 5 = 10
a *= 5; // a = a * 5 = 50
a /= 5; // a = a / 5 = 10
a %= 5; // a = a % 5 = 0
- Conditional Operators: ?: Example:
cssCopy code
int a = 10, b = 20;
int max = (a > b) ? a : b; // max = 20
These are some of the most common operators used in C programming. The use of operators, along with variables and control structures, allows you to create complex expressions and statements that perform specific actions based on the values of variables.
Leave a Comment