# Operators and type's in C

**Operators** are symbols that are used to perform various operations on data, such as variables and constants. Operators are a fundamental part of C and are used to manipulate and process data in different ways. C provides a wide range of operators for performing tasks like arithmetic operations, comparison, logical operations, assignment, and more.

Here '/' is a Arithmetic Operator which divide the value of 'X' to 'Y' and it stored to 'Z'.

#### Types of Operators in C:

Here are some common categories of operators in C:

1. Arithmetic Operator

2. Relational Operators

3. Logical Operators

4. Bitwise Operators

5. Assignment Operators

Operator Type | Operator(s) | Description |
---|---|---|

Arithmetic Operators | +, -, *, /, % | Perform basic arithmetic operations. |

Relational Operators | ==, !=, >, <, >=, <= | Compare values for equality and magnitude. |

Logical Operators | &&, ||, ! | Perform logical operations (AND, OR, NOT). |

Bitwise Operators | &, |, ^, ~, <<, >> | Perform bitwise operations on integer values. |

Assignment Operators | =, +=, -=, *=, /=, %= | Assign and combine values. |

Increment/Decrement | ++ (pre/post), -- (pre/post) | Increase or decrease variable values. |

Conditional Operator | ?: | A ternary operator for conditional expressions. |

#### 1. Arithmetic Operator:

These data types are essential for defining the type of data a variable can store in C and for performing various operations in your C programs.

int main() {

int a = 9, b = 4, c;

c = a + b;

printf("a+b = %d \n",c);

c = a - b;

printf("a-b = %d \n",c);

c = a * b;

printf("a*b = %d \n",c);

c = a / b;

printf("a/b = %d \n",c);

c = a % b;

printf("Remainder when A divided by B = %d \n",c);

return 0;

}

##### Output:

a-b = 5

a*b = 36

a/b = 2

Remainder when A divided by B = 1

#### 2. Relational Operator:

Relational operators compare values. They check if one value equals, is greater than, or is less than another. Examples include "==," which checks equality, ">=" for greater than or equal to, and "<=" for less than or equal to.

int main() {

int a = 10;

int b = 20;

printf("a==b is %d \n",a==b);

printf("a!=b is %d \n",a!=b);

printf("a>b is %d \n",a>b);

printf("a<b is %d \n",a<b);

printf("a>=;b is %d \n",a>=b);

printf("a<=b is %d \n",a<=b);

return 0;

}

##### Output:

a != b is 1

a > b is 0

a < b is 1

a >= b is 0

a <= b is 1

#### 3. Logical Operator:

Relational operators compare values. They check if one value equals, is greater than, or is less than another. Examples include "==," which checks equality, ">=" for greater than or equal to, and "<=" for less than or equal to.

int main() {

int a = 10;

int b = 20;

printf("a==b is %d \n",a==b);

printf("a!=b is %d \n",a!=b);

printf("a>b is %d \n",a>b);

printf("a<b is %d \n",a<b);

printf("a>=;b is %d \n",a>=b);

printf("a<=b is %d \n",a<=b);

return 0;

}

##### Output:

a != b is 1

a > b is 0

a < b is 1

a >= b is 0

a <= b is 1

#### 4. Bitwise Operator:

Bitwise operators are specialized tools in programming that allow you to work directly with the individual bits (0s and 1s) of binary representations of numbers. They take the binary representations of numbers and perform operations like AND, OR, XOR, and shifts on the bits.

These operators are useful when you need to perform operations at the lowest level of data representation, which can be faster and more memory-efficient than traditional mathematical operations.

int main() {

int a = 5;

int b = 3;

// Bitwise AND

int result_and = a & b;

printf("a & b = %d \n",result_and);

// Bitwise OR

int result_or = a | b;

printf("a | b = %d \n",result_or);

// Bitwise XOR

int result_XOR = a ^ b;

printf("a ^ b = %d \n",result_XOR);

return 0;

}

##### Output:

a | b = 7

a ^ b = 6

#### 5. Assignment Operator:

Assignment operators are a fundamental element in programming. They are utilized to store a specific value in a variable. The process is straightforward: the left side of the assignment operator is the variable that will receive the value, and the right side is the value to be stored. It's vital to ensure that the data type of the value on the right side matches the data type of the variable on the left side; otherwise, the code won't compile and will produce an error. This ensures that you're assigning compatible values to your variables, maintaining data consistency in your program.

int main() {

int a = 5;

int b = 3;

int result;

// Assignemt Operator(=)

result = a;

printf("a = %d \n",result);

// Addition Assignment (+=)

result += b;

printf("a += b is %d \n",result);

// Subtraction Assignment (-=)

result -= b;

printf("a -= b is %d \n",result);

// Multiplication Assignment (*=)

result *= b;

printf("a *= b is %d \n",result);

// Division Assignment (*=)

result /= b;

printf("a /= b is %d \n",result);

return 0;

}

##### Output:

a += b is 8

a -= b is 5

a *= b is 15

a /= b is 5