Last Updated:

Variable in delhi

A variable is an area of memory that contains the data that a program operates. When a program manipulates data, it actually operates on the contents of memory cells, i.e., variables.

In order for a program to access a variable (memory area), for example, in order to obtain the initial data for calculating a formula or save the result, the variable must have a name. The name of the variable is invented by the programmer.

You can use a sequence of Latin alphabet letters, numbers, and some special characters as the variable name. The first character in the variable name must be a letter. You cannot use a space in the variable name.

Note that the Delphi compiler does not distinguish between uppercase and lowercase letters in variable names, so the names SUMMA, Summa, and summa denote the same variable.

It is desirable that the name of the variable is logically related to its purpose. For example, variables designed to store the coefficients and roots of a quadratic equation, which is traditionally written in general form:

ах2 + bх + с = 0

It is logical to assign the names a, b, c, x1 and x2.

Another example. If the program has variables designed to store the purchase amount and the discount amount, then these variables can be named: TotalSumm and Discount or ObSumma and Skidka.

In Delphi, every variable must be declared before it can be used. With the help of the declaration, not only the fact of the existence of a variable is established, but also its type is specified, which also indicates the range of valid values.

In general, the statement declaring a variable looks like this:

Имя: тип;

Where is:

  • name — the name of the variable;
  • type—The type of data that the variable is intended to store.

Example:

а: Real; b: Real; i: Integer;

These examples declare two variables of type real and one variable of type integer.

In the text of the program, the declaration of each variable, as a rule, is placed on a separate line.

If your program has multiple variables of the same type, you can list the names of those variables in a single string separated by a comma, and you can specify the type of variables after the name of the last variable by a colon, for example:

а,b,с: Real; x1,x2: Real;