How to define type of constants

For the first time the concept "constant" began to be used in works of the great French physicist and mathematician René Descartes. Coefficients in laws of the nature, density, temperature of melting and conductivity of substances - all this under normal conditions constants. Descartes suggested to call such constants constants, the name it took root in scientific community.

Instruction

1. For creation of a constant in the majority of programming languages there is a reserved word of const. The record ""const [type] [name] [value];"" is necessary for the announcement of a constant. For example: ""const int a 5;"", this record will mean creation of the constant integer an equal to five. The constant can be used in any place of the program code.

2. For creation of a constant it is desirable to choose a name, most precisely it characterizing. This rule especially helps with team work. Notice that the majority of physical and mathematical constants are already busy and established in the program environment; it is possible to get acquainted with them in the specification of a concrete programming language.

3. In programming of a constant are important in many respects thanks to ability to simplify physical models. Number 9.8 is much simpler to dress in Latin letter g, and 3.14 (...) - in the designation pi, than to describe every time these numbers in models. Besides such designations simplify readability of the code and its efficiency.

4. The simplest type of constants - integer. Usual designation for a set of programming languages (SI, C ++, Java, Basic) looks as int or integer. Also division into whole negative, whole positive, long whole, etc. meets. All natural and whole negative numbers belong to this type of constants (for example, 0, 16,-16).

5. Any fractional numbers which are found as constant values belong to type of material constants. Here also the number "пи", and the basis of natural logarithms of e, and the majority of physical constants enters (the last seldom accept the whole values).

6. Symbolical and line constants are actively used in Web programming, bank and social services. The majority of languages allows to unite such symbols and words in groups that it is convenient when cutting excess words in the message and "clever" work with the text. Notice, in the program code the symbolical and lower case constants can not only be written down directly - letters and words. Each symbol has the numerical code which can be used at the announcement of a constant.

7. One more type of constants - Boolean, or values of the validity. They accept logical "zero" or "unit". The code words true and false will help to find them in the text, and they meet usually in conditional designs of if and cycles (for, while).

Author: «MirrorInfo» Dream Team


Print