C Operators

Learn how to use arithmetic, relational, logical, and other operators in C with examples.

C में arithmetic, relational, logical और अन्य operators को उदाहरणों के साथ सीखें।

Operators are symbols used to perform operations on variables and values. C provides various operators like arithmetic (+, -, *), relational (>, <, ==), logical (&&, ||), etc.

Operators वे symbols हैं जिनका उपयोग variables और values पर operations करने के लिए किया जाता है। C में कई प्रकार के operators होते हैं जैसे arithmetic, relational, logical आदि।


Example 1: Addition Operator (+)

#include <stdio.h>

int main() {
    int a = 5, b = 3;
    int sum = a + b;
    printf("Sum = %d", sum);
    return 0;
}

Adds two numbers using `+` operator.

`+` ऑपरेटर का उपयोग दो संख्याओं को जोड़ने के लिए होता है।

Output: Sum = 8


Example 2: Subtraction Operator (-)

#include <stdio.h>

int main() {
    int x = 10, y = 4;
    printf("Difference = %d", x - y);
    return 0;
}

Subtracts two integers using `-`.

`-` ऑपरेटर से दो संख्याओं को घटाया गया है।

Output: Difference = 6


Example 3: Multiplication Operator (*)

#include <stdio.h>

int main() {
    int a = 3, b = 4;
    printf("Product = %d", a * b);
    return 0;
}

Multiplies two integers.

दो integers को गुणा करने के लिए `*` का उपयोग किया गया है।

Output: Product = 12


Example 4: Division Operator (/)

#include <stdio.h>

int main() {
    int a = 10, b = 2;
    printf("Quotient = %d", a / b);
    return 0;
}

Performs integer division.

`/` से integer division किया गया है।

Output: Quotient = 5


Example 5: Modulus Operator (%)

#include <stdio.h>

int main() {
    int a = 10, b = 3;
    printf("Remainder = %d", a % b);
    return 0;
}

Returns remainder using `%` operator.

`%` ऑपरेटर से remainder निकाला गया है।

Output: Remainder = 1


Example 6: Relational Operator (>)

#include <stdio.h>

int main() {
    int a = 7, b = 5;
    printf("%d", a > b);
    return 0;
}

`>` returns 1 if a is greater than b.

`>` ऑपरेटर true होने पर 1 return करता है।

Output: 1


Example 7: Equality Operator (==)

#include <stdio.h>

int main() {
    int x = 10, y = 10;
    printf("%d", x == y);
    return 0;
}

Checks if two values are equal.

दो values को compare करने के लिए `==` का उपयोग।

Output: 1


Example 8: Logical AND (&&)

#include <stdio.h>

int main() {
    int a = 1, b = 0;
    printf("%d", a && b);
    return 0;
}

`&&` returns true only if both conditions are true.

केवल दोनों शर्तें true हों तब `&&` true return करता है।

Output: 0


Example 9: Logical OR (||)

#include <stdio.h>

int main() {
    int x = 0, y = 1;
    printf("%d", x || y);
    return 0;
}

`||` returns true if at least one condition is true.

अगर एक भी condition true हो तो `||` true देता है।

Output: 1


Example 10: Increment Operator (++)

#include <stdio.h>

int main() {
    int x = 5;
    x++;
    printf("%d", x);
    return 0;
}

Increments the value of x by 1.

`++` x का मान 1 से बढ़ा देता है।

Output: 6