What are constants, variables and expressions in programming as well as their classification.
constants
A constant is a numeric or alphanumeric data that does not change during the execution of the program.
Example:
pi = 3.1416
Variable
It is a space in the computer’s memory that allows data to be temporarily stored during the execution of a process; its content can change during the execution of the program.
In order to recognize a variable in the computer’s memory, it is necessary to give it a name with which we can identify it within an algorithm.
Example:
area = pi * radius ^ 2
The variables are: the radius, the area and the constant is pi
Variable Classification
For its content
- Numerical Variables: They are those in which numerical values, positive or negative, are stored, that is, they store numbers from 0 to 9, signs (+ and -) and the decimal point.
Example:
vat = 0.15 pi = 3.1416 cost = 2500 - Logical Variables: They are those that can only have two values (true or false) these represent the result of a comparison between other data.
- Alphanumeric Variables: It is formed by alphanumeric characters (letters, numbers and special characters).
Example:
letter = ‘a’ surname = ‘lopez’ address = ‘Av. Freedom #190’
for its use
- Work Variables: Variables that receive the result of a complete mathematical operation and that are normally used within a program.
Example:
sum = a + b /c
- Counters: They are used to keep track of the number of times an operation is performed or a condition is met. With increments usually one at a time.
- Accumulators: Form that a variable takes and that serves to carry the cumulative sum of a series of values that are read or calculated progressively.
expressions
Expressions are combinations of constants, variables, operation symbols, parentheses, and special function names.
For example:
a + (b + 3) / c
Each expression takes a value that is determined by taking the values of the variables and constants involved and the execution of the indicated operations.
An expression consists of operators and operands. Depending on the type of data they manipulate, expressions are classified into:
- arithmetic
- relational
- logics