2Operators

Operators are fundamental in programming, they allow us to process and modify values.

Operators are crucial, just like in most of programming languages, they allow us to modify & process data or values.

#include <stdio.h>

int main() {
    int a = 8;
    int b = 3;

    printf("a = %d   b = %d\n\n", a, b);

    // 1. Addition and Subtraction
    printf("a + b = %d\n", a + b);   // 11
    printf("a - b = %d\n\n", a - b); // 5

    // 2. Multiplication and Division
    printf("a * b = %d\n", a * b);   // 24
    printf("a / b = %d\n\n", a / b); // 2   (just the whole number)

    // 3. Remainder (modulo)
    printf("a %% b = %d\n\n", a % b); // 2   (what's left after division)

    // 4. Comparison (gives 1 = true, 0 = false)
    printf("Is a bigger than b? %d\n", a > b);    // 1
    printf("Is a equal to b?   %d\n\n", a == b);  // 0

    // 5. Increase by 1
    int count = 5;
    count = count + 1;    // or: count++;
    printf("count became: %d\n", count);  // 6

    return 0;
}

Last updated