Explain different operators in C
1. Arithmetic Operators
These perform mathematical calculations.
Operator Meaning Example
+ Addition c = a + b;
– Subtraction c = a – b;
* Multiplication c = a * b;
/ Division c = a / b;
% Modulus (remainder) c = a % b;
Example:
int a = 10, b = 3;
printf(“%d”, a % b); // Output: 1
2. Relational Operators
These compare two values and return true (1) or false (0).
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than >= Greater than or equal to
<= Less than or equal to Example: if(a > b)
printf(“a is greater”);
3. Logical Operators
Used to combine conditions in decision making.
Operator Meaning
&& Logical AND
! Logical NOT
Example:
if(a > 5 && b < 10)
printf(“Condition is true”);
4. Assignment Operators
Used to assign values to variables.
Operator Example Meaning
= a = 5 Assign 5 to a
+= a += 3 a = a + 3
-= a -= 2 a = a – 2
*= a *= 4 a = a * 4
/= a /= 2 a = a / 2
5. Increment and Decrement Operators
Used to increase or decrease a variable by 1.
Operator Meaning
++ Increment
— Decrement
Example:
int a = 5;
a++; // a becomes 6
6. Bitwise Operators
Operate on binary bits of integers.
Operator Meaning
& Bitwise AND
` `
^ Bitwise XOR
~ Bitwise NOT
<< Left shift >> Right shift
Example:
int a = 5, b = 3;
printf(“%d”, a & b);
7. Conditional (Ternary) Operator
A compact form of if–else.
Syntax:
condition ? expression1 : expression2;
Example:
int max = (a > b) ? a : b;
8. Special Operators
Some special-purpose operators include:
Operator Purpose
sizeof Finds size of a variable
& Address of a variable
* Pointer operator
, Comma operator
Example:
printf(“%lu”, sizeof(int));