There are several types of integer data in the C language. They differ in the range of possible values and whether negative numbers can be used. The main type of integer data is type
int . This type includes signed integers. The range of possible values depends on the computer system for storing this type of
int . Usually one machine word is used. When declaring an integer variable, the keyword defining the type is indicated, then the selected variable name is put and "
; ". Multiple variables can be declared in one statement, separated by commas. The value of a variable can be assigned by the initialization method, i.e. assigning an initial value when declaring.
Example:
int a = 21;
int a = 21, b = -2; Usually in the C language it is assumed that the integer value is written in decimal number system, however, octal and hexadecimal numbers are widely used in programming. In order to mark in which number system the given is recorded, a prefix is placed before it. For the octal number, the prefix is
0 , for hexadecimal -
0x . When using the 8th and 16th systems, it should be remembered that they represent unsigned numbers. C uses three modifications of the basic integer type. The words
short ,
long and
unsigned are used to declare them.
Short data takes up less memory and is signed data.
Long data takes up more memory and is signed data. Unsigned data is used to represent only positive numbers. Their range is offset relative to the
int type.
In C language, when the maximum value is reached, a reset to the minimum value and a reading from it occur. A variety of integer types in the C language is character data type -
char . A character type is declared as well as an integer. Entries for character values are quoted. When assigning a character value, you can use a number code. In this case, the code is written without auxiliary characters.
Example:
char c = "a";
char b = 65; The described method is used to refer to non-printable characters. In the C language, there are another "inconvenient" characters - control sequences.
Sequences | Actions |
\ a | warning (sound signal) |
\ b | return one position |
\ f | page translation |
\ n | line translation |
\ r | carriage return |
\ t | horizontal tab |
\ v | vertical tab |
\\ | display \ |
\ ' | display ' |
\ " | display " |
\ 0 | to output the 8th value |
\ 0x | for displaying the 16th value |
When character sequences are assigned control sequences, they must be enclosed in quotes.
Keywords starting with
_ are included in C compilers, starting with C99 standard. Thus, the keyword
_bool denotes data of a logical type. In the C language, logical data is
true denoted by 1, and
false data - 0. Thus, the logical data are integer. Because Since different computers use different word representations, a difference appears in the ranges of integer values. To refine the ranges, you can use the notation
16_t or
32_t , indicating a 16-bit or 32-bit word representation. Before the word
int you can put the letter
u , indicating the absence of a sign in the format of data representation. In order for the program to recognize the entered notation, it is necessary to attach the
inttypes.h file to
it . When working with the indicated types, a situation may arise when a particular system does not support the type entered. In this regard, the C97 standard defines a second set of names, which ensures that the data type under consideration is at least large enough to meet the requirements of the specification and has the smallest size compared to other similar types. Such data types are called
minimum width data . For example,
int_least8_t means the smallest data type available, storing a
signed 8-bit integer value. In this case, the type can be implemented as a 16-bit value.
In some programs it is necessary to ensure the highest possible speed of execution. For this purpose, the C99 standard has types called the
fastest data types of minimum width . For these types, the prefix is
fast . For example,
int_fast8_t . In the case when it is necessary to use the largest possible integer value,
int_max_t or
uint_max_t are used .
In C, floating-point numbers are
float ,
double, and
longdouble .
The C standard states that
float data must have at least 6 significant digits and a range of values from 10
-37 to 10
37 . For the
double type, the same range of values is set, and the minimum number of significant digits is increased to 10.
For a message about an overflow in standard C99,
inf or
infinity is displayed when the variable value is displayed.
In a situation involving loss of accuracy, a so-called subnormal value. Most often, this value is displayed as zero.
The standard for C99 has added support for complex numbers. For them, there are 3 data types:
float_complex ,
double_complex and
long double_complex . All these types consist of two parts, one of which is real, and the other - imaginary part. When working with these types, you can use the constant
I to denote the square root of -1.
Comments
To leave a comment
Algorithmization and programming. Structural programming. C language
Terms: Algorithmization and programming. Structural programming. C language