Operators in C are symbols that perform specific operations on one or more operands. They are fundamental to C programming, allowing you to manipulate data and control program flow efficiently.
These operators perform mathematical calculations:
+ (addition)- (subtraction)* (multiplication)/ (division)% (modulus)Used for comparing values:
== (equal to)!= (not equal to)> (greater than)< (less than)>= (greater than or equal to)<= (less than or equal to)These operators perform logical operations:
&& (logical AND)|| (logical OR)! (logical NOT)Operate on individual bits of integer values:
& (bitwise AND)| (bitwise OR)^ (bitwise XOR)~ (bitwise NOT)<< (left shift)>> (right shift)Used to assign values to variables:
= (simple assignment)+=, -=, *=, /=, %= (compound assignment)
#include <stdio.h>
int main() {
    int a = 10, b = 5;
    int result;
    result = a + b;
    printf("Addition: %d\n", result);
    result = a - b;
    printf("Subtraction: %d\n", result);
    result *= 2;
    printf("Multiplication and assignment: %d\n", result);
    return 0;
}
    
#include <stdio.h>
int main() {
    int x = 5, y = 10;
    if (x < y && x != 0) {
        printf("x is less than y and not equal to zero\n");
    }
    if (x == 5 || y > 15) {
        printf("Either x is 5 or y is greater than 15\n");
    }
    return 0;
}
    C operators follow a specific order of precedence. Understanding this order is crucial for writing correct expressions. For instance, multiplication has higher precedence than addition.
To deepen your understanding of C operators, explore these related topics:
Mastering C operators is essential for effective C programming. They form the backbone of expressions and control structures in your code. Practice using different operators to become proficient in manipulating data and controlling program flow.