Operators in C Programming

 Here is the complete explanation of Operators in C with syntax and examples:


⭐ Operators in C Programming

Operators are symbols used to perform operations on variables and values.

Example:

int a = 10 + 5;

Here + is an operator.


✔ Types of Operators in C

Category Operators Included
1️⃣ Arithmetic Operators +, -, *, /, %
2️⃣ Relational (Comparison) Operators >, <, >=, <=, ==, !=
3️⃣ Logical Operators &&, ||, !
4️⃣ Assignment Operators =, +=, -=, *=, /=, %=
5️⃣ Increment/Decrement Operators ++, --
6️⃣ Bitwise Operators &, |, ^, ~, <<, >>
7️⃣ Conditional (Ternary) Operator ?:
8️⃣ Special Operators sizeof, &, *, , , ->

πŸ“Œ 1️⃣ Arithmetic Operators

Used to perform mathematical operations.

Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (Remainder)

Example:

int a = 10, b = 3;
printf("%d", a % b); // Output: 1

πŸ“Œ 2️⃣ Relational Operators

Used to compare two values. Output is True(1) / False(0).

Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to

Example:

(a > b)

πŸ“Œ 3️⃣ Logical Operators

Used to combine relational expressions.

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

Example:

if(a > b && a > c)

πŸ“Œ 4️⃣ Assignment Operators

Operator Example Same As
= a = b a = b
+= a += 5 a = a + 5
-= a -= 3 a = a - 3
*= a *= 2 a = a * 2
/= a /= 4 a = a / 4
%= a %= 2 a = a % 2

πŸ“Œ 5️⃣ Increment & Decrement Operators

Operator Meaning
++ Increment (Increase by 1)
-- Decrement (Decrease by 1)

Two Types:

  • Pre: ++a (increment then use)

  • Post: a++ (use then increment)

Example:

int a = 5;
printf("%d", a++); // Output: 5 (then becomes 6)
printf("%d", ++a); // Output: 7

πŸ“Œ 6️⃣ Bitwise Operators

Works on bits (0 or 1).

Operator Meaning
& Bitwise AND
| Bitwise OR
^ XOR
~ NOT
<< Left Shift
>> Right Shift

Example:

int a = 5 << 1;  // 5 = 0101 → 1010 = 10

πŸ“Œ 7️⃣ Conditional / Ternary Operator

Short form of if-else

Syntax:

(condition) ? expression1 : expression2;

Example:

int a = 10, b = 5;
int max = (a > b) ? a : b;

πŸ“Œ 8️⃣ Special Operators

Operator Meaning
sizeof Returns size of data type/variable
& Address of variable
* Pointer dereference
, Comma (evaluate multiple expressions)
-> Used with pointer to access structure member

Example:

int a;
printf("%lu", sizeof(a)); // Size of int

🎯 Operator Precedence (Highest to Lowest)

  1. (), [], ->, .

  2. !, ~, ++, --, (type) cast

  3. *, /, %

  4. +, -

  5. <<, >>

  6. <, <=, >, >=

  7. ==, !=

  8. &

  9. ^

  10. |

  11. &&

  12. ||

  13. ?:

  14. =, +=, -=, etc.

  15. ,


✔ Simple Example Program

#include <stdio.h>
int main() {
    int a = 10, b = 3;
    printf("a+b = %d\n", a+b);
    printf("a>b = %d\n", a>b);
    printf("a&&b = %d\n", a&&b);
    return 0;
}

If you want, I can also give you:
✔ Practice Questions
✔ PDF Notes
✔ MCQs with Answers
✔ Viva Questions

Would you like that?

Comments

Popular posts from this blog

DOWNLOAD THE ANGRY BIRDS MOVIES ALL PARTS IN HINDI IN 720P AND 480P,CAST OF THE ANGRY BIRDS MOVIES

How to download Wonder Women 1984 in hindi in 480p ,720p and 1080p..

What Is C Programming? — Complete Beginner-Friendly Guide