Utilizor
Contact Us
HomeC TutorialC Operators

CC Operators

Performing operations.

C Operators

Operators are used to perform operations on variables and values.

Arithmetic Operators

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulus (Remainer)
  • ++ Increment
  • -- Decrement

Assignment Operators

Assignment operators are used to assign values to variables.

  • =
  • +=
  • -=

Comparison Operators

  • == Equal to
  • != Not equal
  • > Greater than
  • < Less than

Examples

Arithmetic

c example

Basic math operations.

#include <stdio.h>

int main() {
  int x = 10;
  int y = 5;
  printf("%d\n", x + y);
  printf("%d\n", x - y);
  printf("%d\n", x * y);
  printf("%d\n", x / y);
  return 0;
}

Modulus

c example

Remainder of division.

#include <stdio.h>

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

Increment

c example

Increases value by 1.

#include <stdio.h>

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

Comparison

c example

Comparing two values.

#include <stdio.h>

int main() {
  int x = 5;
  int y = 3;
  printf("%d", x > y); // Returns 1 (true) because 5 is greater than 3
  return 0;
}

Test Your Knowledge

1. Which operator returns the remainder?

2. What is the value of x after x++ if x was 5?