Operators in C

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
In C programming language, operators are symbols or keywords that are used to perform operations on variables and values. There are several types of operators in C, which can be broadly categorized as follows:
1. Arithmetic Operators: These operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulus. The arithmetic operators in C are:
- "+" (addition)
- "-" (subtraction)
- "*" (multiplication)
- "/" (division)
- "%" (modulus)
2. Relational Operators: These operators are used to compare values and determine the relationship between them. The relational operators in C are:
- "==" (equal to)
- "!=" (not equal to)
- ">" (greater than)
- ">=" (greater than or equal to)
- "<" (less than)
- "<=" (less than or equal to)
3. Logical Operators: These operators are used to combine and manipulate logical expressions. The logical operators in C are:
- "&&" (logical AND)
- "||" (logical OR)
- "!" (logical NOT)
4. Assignment Operators: These operators are used to assign values to variables. The assignment operators in C are:
- "=" (simple assignment)
- "+=" (addition assignment)
- "-=" (subtraction assignment)
- "*=" (multiplication assignment)
- "/=" (division assignment)
- "%=" (modulus assignment)
5. Increment and Decrement Operators: These operators are used to increase or decrease the value of a variable by one. The increment and decrement operators in C are:
- "++" (increment)
- "--" (decrement)
6. Bitwise Operators: These operators are used to perform bitwise operations on variables. The bitwise operators in C are:
- "&" (bitwise AND)
- "|" (bitwise OR)
- "^" (bitwise XOR)
- "
In C programming language, operators are symbols or keywords that are used to perform operations on variables and values. There are several types of operators in C, which can be broadly categorized as follows: 1. Arithmetic Operators: These operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulus. The arithmetic operators in C are: - "+" (addition) - "-" (subtraction) - "*" (multiplication) - "/" (division) - "%" (modulus) 2. Relational Operators: These operators are used to compare values and determine the relationship between them. The relational operators in C are: - "==" (equal to) - "!=" (not equal to) - ">" (greater than) - ">=" (greater than or equal to) - "<" (less than) - "<=" (less than or equal to) 3. Logical Operators: These operators are used to combine and manipulate logical expressions. The logical operators in C are: - "&&" (logical AND) - "||" (logical OR) - "!" (logical NOT) 4. Assignment Operators: These operators are used to assign values to variables. The assignment operators in C are: - "=" (simple assignment) - "+=" (addition assignment) - "-=" (subtraction assignment) - "*=" (multiplication assignment) - "/=" (division assignment) - "%=" (modulus assignment) 5. Increment and Decrement Operators: These operators are used to increase or decrease the value of a variable by one. The increment and decrement operators in C are: - "++" (increment) - "--" (decrement) 6. Bitwise Operators: These operators are used to perform bitwise operations on variables. The bitwise operators in C are: - "&" (bitwise AND) - "|" (bitwise OR) - "^" (bitwise XOR) - "
In C programming language, operators are symbols or keywords that are used to perform operations on variables and values. There are several types of operators in C, which can be broadly categorized as follows:

1. Arithmetic Operators: These operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulus. The arithmetic operators in C are:

- "+" (addition)
- "-" (subtraction)
- "*" (multiplication)
- "/" (division)
- "%" (modulus)

2. Relational Operators: These operators are used to compare values and determine the relationship between them. The relational operators in C are:

- "==" (equal to)
- "!=" (not equal to)
- ">" (greater than)
- ">=" (greater than or equal to)
- "<" (less than)
- "<=" (less than or equal to)

3. Logical Operators: These operators are used to combine and manipulate logical expressions. The logical operators in C are:

- "&&" (logical AND)
- "||" (logical OR)
- "!" (logical NOT)

4. Assignment Operators: These operators are used to assign values to variables. The assignment operators in C are:

- "=" (simple assignment)
- "+=" (addition assignment)
- "-=" (subtraction assignment)
- "*=" (multiplication assignment)
- "/=" (division assignment)
- "%=" (modulus assignment)

5. Increment and Decrement Operators: These operators are used to increase or decrease the value of a variable by one. The increment and decrement operators in C are:

- "++" (increment)
- "--" (decrement)

6. Bitwise Operators: These operators are used to perform bitwise operations on variables. The bitwise operators in C are:

- "&" (bitwise AND)
- "|" (bitwise OR)
- "^" (bitwise XOR)
- "

" (bitwise NOT)
- "<<" (left shift) - ">>" (right shift)

Here's an example of how to use some of these operators in C:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
int main() {
int a = 10, b = 5;
// Arithmetic operators
printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
printf("a * b = %d\n", a * b);
printf("a / b = %d\n", a / b);
printf("a %% b = %d\n", a % b);
// Relational operators
printf("a == b is %d\n", a == b);
printf("a != b is %d\n", a != b);
printf("a > b is %d\n", a > b);
printf("a >= b is %d\n", a >= b);
printf("a < b is %d\n", a < b);
printf("a <= b is %d\n", a <= b);
// Logical operators
printf("(a > 5) && (b < 10) is %d\n", (a > 5) && (b < 10));
printf("(a > 5) || (b > 10) is %d\n", (a > 5) || (b > 10));
printf("!(a > 5) is %d\n", !(a > 5));
// Assignment operators
a += 5;
printf("a += 5 is %d\n", a);
b *= 2;
printf("b *= 2 is %d\n", b);
// Increment and decrement operators
a++;
printf("a++ is %d\n", a);
b--;
printf("b-- is %d\n", b);
// Bitwise operators
int c = 0b1010, d = 0b1100;
printf("c & d = %d\n", c & d);
printf("c | d = %d\n", c | d);
printf("c ^ d = %d\n", c ^ d);
printf("</stdio.h>
#include <stdio.h> int main() { int a = 10, b = 5; // Arithmetic operators printf("a + b = %d\n", a + b); printf("a - b = %d\n", a - b); printf("a * b = %d\n", a * b); printf("a / b = %d\n", a / b); printf("a %% b = %d\n", a % b); // Relational operators printf("a == b is %d\n", a == b); printf("a != b is %d\n", a != b); printf("a > b is %d\n", a > b); printf("a >= b is %d\n", a >= b); printf("a < b is %d\n", a < b); printf("a <= b is %d\n", a <= b); // Logical operators printf("(a > 5) && (b < 10) is %d\n", (a > 5) && (b < 10)); printf("(a > 5) || (b > 10) is %d\n", (a > 5) || (b > 10)); printf("!(a > 5) is %d\n", !(a > 5)); // Assignment operators a += 5; printf("a += 5 is %d\n", a); b *= 2; printf("b *= 2 is %d\n", b); // Increment and decrement operators a++; printf("a++ is %d\n", a); b--; printf("b-- is %d\n", b); // Bitwise operators int c = 0b1010, d = 0b1100; printf("c & d = %d\n", c & d); printf("c | d = %d\n", c | d); printf("c ^ d = %d\n", c ^ d); printf("</stdio.h>
#include 

int main() {
    int a = 10, b = 5;

    // Arithmetic operators
    printf("a + b = %d\n", a + b);
    printf("a - b = %d\n", a - b);
    printf("a * b = %d\n", a * b);
    printf("a / b = %d\n", a / b);
    printf("a %% b = %d\n", a % b);

    // Relational operators
    printf("a == b is %d\n", a == b);
    printf("a != b is %d\n", a != b);
    printf("a > b is %d\n", a > b);
    printf("a >= b is %d\n", a >= b);
    printf("a < b is %d\n", a < b);
    printf("a <= b is %d\n", a <= b);

    // Logical operators
    printf("(a > 5) && (b < 10) is %d\n", (a > 5) && (b < 10));
    printf("(a > 5) || (b > 10) is %d\n", (a > 5) || (b > 10));
    printf("!(a > 5) is %d\n", !(a > 5));

    // Assignment operators
    a += 5;
    printf("a += 5 is %d\n", a);
    b *= 2;
    printf("b *= 2 is %d\n", b);

    // Increment and decrement operators
    a++;
    printf("a++ is %d\n", a);
    b--;
    printf("b-- is %d\n", b);

    // Bitwise operators
    int c = 0b1010, d = 0b1100;
    printf("c & d = %d\n", c & d);
    printf("c | d = %d\n", c | d);
    printf("c ^ d = %d\n", c ^ d);
    printf("

c = %d\n",

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
c);
printf("c << 2 = %d\n", c << 2);
printf("d >> 2 = %d\n", d >> 2);
return 0;
}
c); printf("c << 2 = %d\n", c << 2); printf("d >> 2 = %d\n", d >> 2); return 0; }
c);
    printf("c << 2 = %d\n", c << 2);
    printf("d >> 2 = %d\n", d >> 2);

    return 0;
}

In this example, we define two variables a and b and demonstrate the use of various operators, including arithmetic, relational, logical, assignment, increment and decrement, and bitwise operators.