bscodinglab

Operators In C

In C programming, operators are symbols that represent specific actions or calculations. Operators are used to manipulate values and perform operations in a program. Here are the different types of operators in C:

Operator Type Description
Arithmetic
Used to perform mathematical calculations on numeric values, such as addition, subtraction, multiplication, division, and module.
Relational
Used to compare two values and determine their relationship, such as less than, greater than, equal to, and not equal to.
Logical
Used to perform logical operations on boolean values, such as logical AND, logical OR, and logical NOT.
Bitwise
Used to manipulate individual bits of a numeric value, such as bitwise AND, bitwise OR, and bitwise XOR.
Assignment
Used to assign a value to a variable, such as simple assignment, add and assign, and bitwise OR and assign.
Conditional
Used to perform a conditional operation, such as the ternary operator.
Miscellaneous
Used for various purposes, such as the address-of operator, the pointer operator, and the size-of operator.

Operators are an essential part of programming, and understanding their behavior and usage is critical for writing efficient and effective programs. Table of operators example with its name and sign .

Arithmetic Operators
Operator NameOperator SignExample
Addition+int sum = 3 + 5;
Subtraction-int difference = 7 - 2;
Multiplication*int product = 4 * 6;
Division/float quotient = 10.0 / 3.0;
Modulo/Remainder%int remainder = 10 % 3;
Increment++int x = 5; x++;
Decrement--int y = 7; y--;
Relational Operators
Operator NameOperator SignExample
Less Than<if (x < y) { ... }
Greater Than>if (x > y) { ... }
Less Than or Equal To<=if (x <= y) { ... }
Greater Than or Equal To>=if (x >= y) { ... }
Equal To==if (x == y) { ... }
Not Equal To!=if (x != y) { ... }
Logical Operators
Operator NameOperator SignExample
Logical AND&&if (x > 0 && y > 0) { ... }
Logical OR||if (x > 0 || y > 0) { ... }
Logical NOT!if (!(x > 0)) { ... }
Bitwise Operators
Operator NameOperator SignExample
Bitwise AND&int z = x & y;
Bitwise OR|int z = x | y;
Bitwise XOR^int z = x ^ y;
Bitwise NOT~int z = ~x;
Left Shift<<int z = x << 3;
Right Shift>>int z = x >> 2;
Assignment Operators
Operator NameOperator SignExample
Simple Assignment=x = 42;
Add and Assign+=x += 5;
Subtract and Assign-=x -= 3;
Multiply and Assign*=x *= 2;
Divide and Assign/=x /= 3;
Modulo and Assign%=x %= 2;
Bitwise AND and Assign&=x &= 0xFF;
Bitwise OR and Assign|=x |= 0x80;
Bitwise XOR and Assign^=x ^= 0x0F;
Left Shift and Assign<<=x <<= 2;
Right Shift and Assign>>=x >>= 1;
Conditional Operator
Operator NameOperator SignExample
Ternary Operator? :int max = (x > y) ? x : y;