These materials are very useful for your reference! Data is stored in a computer in a certain type and format. Data types can be integers, real numbers, characters or graphics, images, sounds and videos. In C language, data types can be divided into four categories: basic data type, structural data type (including array, enumeration type, structure and association), pointer type and null type. This section introduces the basic data types of C language: integer, floating-point and character. In C language, data can be divided into constants and variables. A constant refers to an amount whose value cannot be changed during the running of a program, while a variable can be changed. 2.2. The integer constant of1integer is an integer constant, and the commonly used integer constants in C language are hexadecimal, octal and decimal. Hexadecimal integer constants have a prefix of 0x, and the values are 0 ~ 9, a ~ f (or a ~ f, respectively corresponding to the numbers 10 ~ 15). For example, 0x 1A6, its corresponding decimal value is/kloc-0 /×162+161+6×160 = 422. The following numbers are legal hexadecimal integer constants. 0x25 (decimal 37), 0xB 1 (decimal 177), 0xFFFF (decimal 65535). The following numbers are not legal hexadecimal integer constants: 12 (without the prefix 0x, the computer will treat it as decimal 12), and 0x 12G(G is not a legal hexadecimal number). Octal integer constants must be prefixed with 0, and their values are 0 ~ 7. For example, 0 15, its corresponding decimal number is1× 81+5× 80 =13. The following numbers are legal octal integer constants. 0 12 (decimal 10), 010/(decimal 65), 0 1000 (decimal 5 12). The following numbers are not legal octal numbers: 256 (without prefix 0), 03A2 (including non-octal numbers). Decimal integer constants have no prefix, and their values range from 0 to 9. The following numbers are legal decimal integer constants. 237,65535, 1688。 The following numbers are not legal decimal integer constants. 025 (without leading 0), 88D (including non-decimal digits). Variables in C language follow the rule of "define before use". The following defines an integer variable named num, then assigns it to 100, and then changes its value to 200. int numnum = 100; Num = 200Int is the basic type of integer variables, and there are also short integers (short int or short) and long integers (long int or long). The difference between them lies in the number of bytes occupied by variables when they are stored in memory. Usually on a 32-bit computer, the short integer is 2 bytes, that is, 16 bits, and the basic integer and the long integer occupy 4 bytes, that is, 32 bits. For example, there is the following statement, which defines a short integer variable I and gives it an initial value 10 when defining it. short int I = 10; Data is stored in memory in binary form, and the binary number corresponding to decimal number 10 is 10 10. Figure 2- 1 shows the storage of variable I in memory, with the highest bit being the sign bit, 0 being a positive number and 1 being a negative number. Figure 2-Memory example of1variable I Figure What is the range of short integer short integer variable? 6? 12 15~2 15? 6? 1 1, that is? 6? 132768~32767。 The number represented by short integers is very limited. Int type is usually used in practical applications, and the range of values is? 6? 123 1~23 1? 6? 1 1, that is? 6? 12 147483638~2 147483637。 In some practical applications, the values of variables are often positive, such as the total number of books in the library management system and the number of company employees in the enterprise information system. In order to make full use of the representation range of variables, variables can be defined as unsigned types at this time. Adding the modifier unsigned can define unsigned variables, such as unsigned short int i, and define an unsigned short integer variable I; Unsigned int j defines an unsigned integer variable j. By default, the defined variable is signed, that is, the number can be positive or negative, and the signed variable can also be added with the modifier signed, but it is usually not added. The value range of unsigned short integer is 0 ~ 2 16, because most significant bit no longer stores symbolic information. 6? 1 1, which is 0 ~ 65535. Accordingly, the number represented by unsigned integers ranges from 0 to 232? 6? 1 1, namely 0 ~ 4294967295. The number of bytes occupied by each data type is not specified in C language, and how to realize it is determined by each computer system. On some microcomputers, both short integer and integer are 16 bits, and long integer is 32 bits. The number of bytes in memory can be determined by looking up the operation symbol sizeof for the number of bytes. Example 2-2 The program can be used to determine the number of bytes occupied by each data type. Example 2-2 # includes
Please use music score.