Operators

Understanding Operators in C Programming

Introduction to Operators (ऑपरेटर्स का परिचय)

Operators symbols हैं जो variables और values पर operations perform करते हैं। C में विभिन्न प्रकार के operators होते हैं।

Operators are symbols that perform operations on variables and values. C has various types of operators.

Key Points (मुख्य बिंदु):

  • Operators को उनके functionality के according categorize किया जाता है
  • Operators are categorized according to their functionality
  • प्रत्येक operator का अपना precedence और associativity होता है
  • Each operator has its own precedence and associativity
  • Operators का उपयोग expressions बनाने के लिए किया जाता है
  • Operators are used to form expressions

Arithmetic Operators (अंकगणितीय ऑपरेटर्स)

Arithmetic operators mathematical operations perform करते हैं:

Arithmetic operators perform mathematical operations:

Operator (ऑपरेटर) Description (विवरण) Example (उदाहरण)
+ Addition (जोड़) a + b
+ Addition a + b
- Subtraction (घटाव) a - b
- Subtraction a - b
* Multiplication (गुणा) a * b
* Multiplication a * b
/ Division (भाग) a / b
/ Division a / b
% Modulus (शेष) a % b
% Modulus a % b
// Arithmetic operators example
int a = 10, b = 3;
int sum = a + b;      // 13
int difference = a - b; // 7
int product = a * b;   // 30
int quotient = a / b;  // 3
int remainder = a % b; // 1

Relational Operators (संबंधपरक ऑपरेटर्स)

Relational operators values के बीच comparison करते हैं:

Relational operators compare values:

Operator (ऑपरेटर) Description (विवरण) Example (उदाहरण)
== Equal to (बराबर) a == b
== Equal to a == b
!= Not equal to (असमान) a != b
!= Not equal to a != b
> Greater than (बड़ा) a > b
> Greater than a > b
< Less than (छोटा) a < b
< Less than a < b
// Relational operators example
int a = 10, b = 20;
if (a < b) {
    printf("a is less than b\n");
}
if (a != b) {
    printf("a is not equal to b\n");
}

Logical Operators (तार्किक ऑपरेटर्स)

Logical operators multiple conditions को combine करते हैं:

Logical operators combine multiple conditions:

Operator (ऑपरेटर) Description (विवरण) Example (उदाहरण)
&& Logical AND (और) a && b
&& Logical AND a && b
|| Logical OR (या) a || b
|| Logical OR a || b
! Logical NOT (नहीं) !a
! Logical NOT !a
// Logical operators example
int age = 25;
int hasLicense = 1;

if (age >= 18 && hasLicense) {
    printf("Can drive\n");
}
if (!hasLicense) {
    printf("Cannot drive\n");
}

Operator Precedence (ऑपरेटर प्राथमिकता)

Operator precedence define करता है कि कौन सा operation पहले evaluate होगा:

Operator precedence defines which operation is evaluated first:

Precedence (प्राथमिकता) Operators (ऑपरेटर्स)
Highest (सबसे ऊंची) () [] -> .
Highest () [] -> .
High (ऊंची) ! ~ ++ -- + - * &
High ! ~ ++ -- + - * &
Medium (मध्यम) * / %
Medium * / %
Low (कम) + -
Low + -
// Operator precedence example
int result = 5 + 3 * 2;  // Result is 11, not 16
// Multiplication (*) has higher precedence than addition (+)

Best Practices (सर्वोत्तम प्रथाएं)

Operators के साथ काम करने के best practices:

Best practices for working with operators:

  • Parentheses: Complex expressions में parentheses का use करें
  • Parentheses: Use parentheses in complex expressions
  • Readability: Code को readable बनाने के लिए spaces का use करें
  • Readability: Use spaces to make code readable
  • Type Safety: Type conversion को carefully handle करें
  • Type Safety: Handle type conversion carefully
  • Documentation: Complex operations को document करें
  • Documentation: Document complex operations