Introduction
Operators help us do math and make decisions in programs easily. They let us add, compare, and change values quickly.
Operators help us do math and make decisions in programs easily. They let us add, compare, and change values quickly.
result = operand1 operator operand2;
Operands are the values or variables you work with.
Operators tell the computer what to do with those values.
int sum = 5 + 3;
int isBigger = (7 > 4);
int remainder = 10 % 3;
This program shows how operators do math with two numbers and print the results.
#include <stdio.h> int main() { int a = 10; int b = 3; int sum = a + b; int diff = a - b; int product = a * b; int quotient = a / b; int remainder = a % b; printf("Sum: %d\n", sum); printf("Difference: %d\n", diff); printf("Product: %d\n", product); printf("Quotient: %d\n", quotient); printf("Remainder: %d\n", remainder); return 0; }
Operators make code shorter and easier to read than writing long instructions.
Using the wrong operator can cause bugs, so choose carefully.
Operators let you do math and comparisons in code.
They work with values to produce new results.
Using operators correctly helps your program make decisions and calculations.
int a = 10, b = 3;
int result = a / b;
printf("%d", result);int x = 5;
int y = 10;
if (x = y) {
printf("Equal");
} else {
printf("Not Equal");
}Pass the test and this pattern moves unknown