Hey, everybody welcome to the 3rd part of this series. Learning fundamentals of programming like a 5 years old, before learning any programming language.
Operators
Operators are special symbols that perform operations on variables and values, while expressions are combinations of variables, values, and operators that produce new results.
Let's understand more clearly. Basically, mathematical operations like addition, subtraction, division, and finding the remainder are represented by specific symbols. These symbols are used in programming so that the computer understands which mathematical operation to perform.
Addition: Represented by +
Subtraction: Represented by -
Division: Represented by /
Remainder (modulo): Represented by % (this will output the remainder after division)
Now let's see them in action:
int a = 2, b = 4, c = 0; //you can declare 3 variables together like this
c = a+b; //this will output 6, because 2+4=6
c = b-a; //this will output 2, because 4-2=2
c = b/a; //this will output 2, because 4 divided by 2 = 2
c = b%a; //this will output 0, because the remainder when dividing 4 by 2 is 0 (since 4 is perfectly divisible by 2)
Expressions
Expressions are combinations like a + b, b - a, Ext.
Top comments (0)