Integer variables are used to store integers.
Integer variables can be divided into several types. The most basic integer variable is a symbolic integer declared by the type specifier int, in the following form:
Int counter;
Here int is the type specifier and Counter is the name of the variable.
Integer variables can be signed, unsigned, long integer, short integer or ordinary signed integers as defined above.
Integer is 16 bits, long integer is 32 bits, and short integer is equivalent to integer.
The following are examples of declarations of several integer variables:
Long int amount; /* Long integer */
Long quantity; /* Long integer, equivalent to */
Signed integer total; /* signed integer */
The total number of signs; /* Signed integer, equivalent to */
Unsigned integer offset; /* unsigned integer */
Unsigned offset; /* unsigned integer, equivalent to */
Short int SmallAmt/* short integer */
Short and small; /* Short integer, equivalent to */
Unsigned short integer month; /* unsigned short integer */
Unsigned short month; /* unsigned short integer, equivalent to */
As can be seen from the above example, when defining long integer, short integer, signed integer or unsigned integer, the keyword int can be omitted.
note:
1. There is no need to sign integer variables with signed, because integers are signed unless they are unsigned.
2. When a variable has several characteristics, the order of declaring keywords can be arbitrary. The following statements are equivalent:
Unsigned long integer t1;
Long unsigned T2;
Unsigned long integer T3;
Unsigned int long T4;;
Long unsigned integer t5;
Long integer unsigned T6;
Int unsigned long integer t7;
Int long unsigned t8;
(3) Floating-point variables
As the name implies, floating-point variables are used to store real numbers with decimals.
There are three different floating-point types in C language. The following are examples of these three different types of declarations:
Floating amount; /* Single precision type */
Double BigAmount/* double precision type */
Long Double ReallyBigmount/* Long Double Type */
Amount, bigamount and reallybigmount here are all variable names.
Floating-point types are signed.
(4) Character variables
Characters stored in character variables are characters in the computer character set. For C system running on PC, character data is represented by 8-bit single-byte ASCII code. The program uses the type specifier char to declare character variables:
char ch
This declaration statement declares a character variable with the identifier ch. When a variable is declared in this form, the program can refer to it in an expression, and the knowledge about statements and expressions will be introduced later.
Character data type is actually an 8-bit integer data type, which can be used in numerical expressions, just like other integer data. In this case, the character variable can be signed or unsigned. For unsigned character variables, it can be declared as:
Unsigned character ch;
Unless declared unsigned, character variables are usually regarded as 8-bit signed integer variables in arithmetic and comparison operations.
There are also pointer variables, void variables and other variables, which will be introduced later.
Second, constant
A constant is a constant. Like variables, constants are divided into integer constants, floating-point constants, character constants, string constants, escaped character constants and address constants.
(1) integer constant
Integer constants can be long, short, signed or unsigned. In Tubbo C 2.0, the signed integer constants range from -32768 to 32767, and the unsigned integer constants range from 0 to 65535; Signed long integers range from -2 147483648 to 2 147483647. The range of unsigned long integers is 0 to 4294967295. Short integer homographs.
You can specify integer constants as binary, octal or hexadecimal, as shown in the following statement:
- 129,0x 12fe,0 177
A constant is preceded by the symbol 0x, indicating that it is a hexadecimal representation. If the preceding symbol has only one letter 0, it means that the constant is octal.
Sometimes we add the symbol L or U after a constant to indicate whether the constant is a long integer or an unsigned integer:
22388L,0x4efb2L,40000U
Suffixes can be uppercase or lowercase.
(2), floating-point constant
Floating-point constants consist of an integer and a decimal, separated by decimal points. Some floating-point trees are too big or too small to be easily expressed by ordinary methods, and can be expressed by scientific counting method or exponential method. Here is an example:
3. 14 16, 1.234E-30,2.47E20 1
Note that in C language, the size of numbers is also limited. Float floating point number, the number range is -3.402823E38 to 3.402823E38, where-1.40 1298E-45 to 1.40 1298E-45 are invisible. The expression range of double floating-point constants is-1.79E308 to 1.79E308, where -4.94E-324 to 4.94E-324 are invisible.
We can also add suffixes to floating-point constants.
float number = 1.6e 10F; /* Signed floating-point type */
LongDoubleNumber = 3.45L/* Long double precision type */
Suffixes can be uppercase or lowercase.
Description:
1. Floating-point constant has only one decimal system.
2. By default, all floating-point constants are double-precision.
3. If the absolute value is less than 1, the zero before the decimal point can be omitted. For example, 0.22 can be written as .222, and -0.00 15E-3-3 can be written as -.00 15E-3.
4. When 4.Turbo C outputs floating-point numbers in the default format, only 6 decimal places are reserved at most.
(3) Characteristic constant
The value represented by a character constant is the value that a character variable can contain. We can use ASCII expressions to represent a character constant, or use single quotation marks and backslashes to represent escape characters.
a ',' \x2f ',' \ 0 13 ';
Where: \x means that the following characters are hexadecimal numbers, and \0 means that the following characters are octal numbers.
Note: In Turbo C 2.0, the range of numbers represented by character constants is-128 to 127, unless it is declared unsigned, that is, 0 to 255.
(4), string constants
String constants are strings enclosed in double quotes.
hello,world
\ n Enter a selection:
\ a mistake! ! !