What are Operators ???
Operators are symbols which are used to perform operations of operands. In simple words, they are like the tools which helps to manipulate data in our program or also in simple words we say that Operators are used to make a Mathematical Calculation things like Adding, Subtracting, etc.
What are Expression ???
A set of values, variables, and operators combined to produce a single value is called a Expression. Expression can Range in complexity from a single value to a combination of several processes.
Types of Operators
In C Language we have Five Types of Operators,
- Arithmetic Operator
- Relational Operator
- Logical Operator
- Assignment Operator
- Increment and Decrement Operator
C Language Notes
1. Arithmetic Operator
Arithmetic is mainly used For Mathematical Operations Like, Addition , Subtraction, etc.
Name of Operator | Symbol of Operator |
Addition | + |
Subtraction | – |
Multiplication | * |
Division | / |
Modulus | % |
2. Relational Operator
Relational Operators are used to compare values Like Less than, Greater than, etc.
Name of Operator | Symbol of Operator |
Equal to | == |
Not Equal to | != |
Less Than | < |
Greater Than | > |
Less than or Equal to | <= |
Greater than or Equal to | >= |
3. Logical Operator
Logical Operators are used to perform a logical operations.
Name of Operator | Symbol of Operator |
Logical AND | && |
Logical OR | || |
Logical NOT | ! |
4. Assignment Operator
Assignment Operators are help us to assign the values in our program.
Name of Operator | Symbol of Operator |
Assign | = |
Add and Assign | += |
Subtract and Assign | -= |
Multiply and Assign | *= |
Divide and Assign | /= |
Modulus and Assign | %= |
5. Unary Operator
Unary operators are act on a single operand.
Name of Operator | Symbol of Operator |
Increment | ++ |
Decrement | — |
Negation | – |
Logical NOT | ! |
Example : Operators and Expression
Let’s write a Program Where we write Expression with the use of Operators.
#include <stdio.h> int main() { // Arithmetic Operators int num1 = 10, num2 = 5; int sum = num1 + num2; int difference = num1 - num2; int product = num1 * num2; float quotient = (float)num1 / num2; // Typecasting to get accurate division int remainder = num1 % num2; // Output printf("Sum: %d\n", sum); printf("Difference: %d\n", difference); printf("Product: %d\n", product); printf("Quotient: %.2f\n", quotient); printf("Remainder: %d\n", remainder); return 0; }
- In this Program First we declare a Variables, Second We assign the values to that variables, and Lastly We create expression by using the Operators.