Operator in c programming language
π₯Operators in C Programming Language (In Detail)
In C programming, an operator is a symbol that tells the compiler to perform a specific mathematical or logical operation on variables and values.
π Example:
C
a + b
Here,
+ is an operator and a, b are operands.
πΉ Types of Operators in C Language
1. Arithmetic Operators
Used to perform basic mathematical operations.
Operator Meaning Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus a % b
π Example:
C
int sum = a + b;
int rem = a % b;
2. Relational Operators
Used to compare two values.
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater or equal to
<= Less or equal to
π Output is always True (1) or False (0)
C
if(a > b)
3. Logical Operators
Used to combine two or more conditions.
Operator Meaning
&& Logical AND
! Logical NOT
π Example:
C
if(a>10 && b<5)
4. Assignment Operators
Used to assign values to variables.
Operator Example Meaning
= a = 5 Assign value
+= a += 2 a = a + 2
-= a -= 2 a = a - 2
*= a *= 2. a = a * 2
/= a /= 2 a = a / 2
%= a %= 2 a = a % 2
5. Increment & Decrement Operators
Operator Meaning
++ Increment
-- Decrement
π Types:
Pre Increment → ++a (increase first, then use)
Post Increment → a++ (use first, then increase)
Example:
C
a++;
--b;
6. Bitwise Operators
Used to perform operations at bit level.
Operator Meaning
& AND
| OR
^ XOR
~ NOT
<< Left Shift
>> Right Shift
7. Conditional (Ternary) Operator
Syntax:
C
condition ? expression1 : expression2;
π Example:
C
max = (a>b) ? a : b;
8. Special Operators
Operator Use
sizeof Find memory size
& Address of variable
* Pointer operator
, Comma operator
Example:
C
sizeof(int);
πΉ Operator Precedence
Operator precedence decides which operator will be evaluated first.
Example:
C
int result = 10 + 5 * 2;
π Output = 20
Comments
Post a Comment