Operators in C are special symbols that perform specific operations on one, two, or three operands, and then return a result. C supports a wide variety of operators, including arithmetic, relational, logical, bitwise, assignment, and others. In this article, we will discuss the different types of operators in C and provide examples of how to use them in your code.

## Operators in C

### 1. Arithmetic Operators

Arithmetic operators are used to perform basic mathematical operations, such as addition, subtraction, multiplication, and division.

Examples:

- Addition (+)
- Subtraction (-)
- Multiplication (*)
- Division (/)
- Modulus (%)
- Increment (++)
- Decrement (--)

For example, the following code demonstrates the use of arithmetic operators:

### 2. Relational Operators

Relational operators are used to compare two operands and return a Boolean value indicating whether the comparison is true or false.

Examples:

- Less than (<)
- Greater than (>)
- Less than or equal to (<=)
- Greater than or equal to (>=)
- Equal to (==)
- Not equal to (!=)

For example, the following code demonstrates the use of relational operators:

### 3. Logical Operators

Logical operators are used to perform logical operations, such as AND, OR, and NOT.

Examples:

- Logical AND (&&)
- Logical OR (||)
- Logical NOT (!)

For example, the following code demonstrates the use of logical operators:

### 4. Bitwise Operators

Bitwise operators are used to perform bitwise operations, such as AND, OR, NOT, and XOR.

Examples:

- Bitwise AND (&)
- Bitwise OR (|)
- Bitwise NOT (~)
- Bitwise XOR (^)
- Left shift (<<)
- Right shift (>>)

For example, the following code demonstrates the use of bitwise operators:

### 5. Assignment Operators

Assignment operators are used to assign a value to a variable. The most basic assignment operator is the equal sign (=), which assigns the value on the right to the variable on the left.

Examples:

- Basic assignment (=)
- Addition assignment (+=)
- Subtraction assignment (-=)
- Multiplication assignment (*=)
- Division assignment (/=)
- Modulus assignment (%=)
- Left shift assignment (<<=)
- Right shift assignment (>>=)
- Bitwise AND assignment (&=)
- Bitwise OR assignment (|=)
- Bitwise XOR assignment (^=)

For example, the following code demonstrates the use of assignment operators:

### 6. Conditional (ternary) operator

The conditional operator is also known as the ternary operator. It is represented by the ? symbol. It is used to perform a simple if-else condition in a single line.

Syntax: condition ? if_true_value : if_false_value;

Example:

### 7. sizeof() operator

The sizeof operator returns the size of a variable or data type in bytes.

Example:

### Conclusion

In conclusion, operators in C are special symbols that perform specific operations on one, two, or three operands, and then return a result.

C supports a wide variety of operators, including arithmetic, relational, logical, bitwise, assignment, and others. Understanding how to use operators in C can make your code more efficient and easier to read and understand.

It's important to note that in C and C++, the order of operations follows the order of precedence and associativity of the operators. Be sure to understand the order of precedence and associativity of the operators and use parenthesis when necessary to ensure the code produces the expected results.

**Next Post >**