Constant constants refer to those quantities that cannot be changed during the execution of a program. C language constants include direct constants and symbolic constants. First, direct constants can be used directly in programs and can be divided into the following basic types. 1. Integer constant: It is an integer. There are usually three forms of expression: octal, decimal and hexadecimal. C language stipulates that octal numbers must start with 0, and hexadecimal numbers must start with 0X or 0x. For example, the decimal constant 10 is written as 0 12 in octal and 0XA or 0xa in hexadecimal. To avoid confusion with octal, decimal integer constants cannot be preceded by invalid 0, for example, 10 cannot be written as 0 10. 2. Long integer constants: All integers within the design range of long type can be regarded as long integer constants. When writing, add an English character L or L after the constant. Such as -28l or -28L (decimal long integer constant), 056L or 056l (octal long integer constant), 0X33DL or 0x33dl (hexadecimal long integer constant). 3. Floating-point constant: it is a real number, and there is only one expression of decimal. Its writing form is as follows: (1) Representation of decimals. Such as:-1.25, 0.452. (2) Exponential representation. This representation is usually used for large or small numbers encountered in calculation. For example, 60000 can be expressed as 6E4, 0.000035 can be written as 3.5E-5 and so on. E can also be written in lowercase e.4. Character constant: It is a numerical constant, which uses characters to represent the coded values of characters in the machine character set, such as ASCII code values used by IBMPC series microcomputers. It is written in single quotation marks, such as''''''' a''''''''. Since the ASCII code of the character A is 65, taking the character constant'''''''' A'''''', the actual value is 65. In addition, you can put the escape characters introduced in the table 1. 1 in single quotation marks as character constants. If''''''' \n''''' is used to represent the ASCII code 10 of a line break. In the escape character series, the backslash "\" changes the original meaning of the following character n.5. String constant: a constant consisting of zero or more characters. Enclose these characters in double quotation marks when writing. Such as "one" and "world". Characters that make up a string can include escape character sequences listed in the table 1. 1. For example, "CHINA\nHEFEI\n" runs this string as the parameter of the library function printf, and the following results will be printed on the screen: When compiling Chinese Hefei string constants, the compilation system automatically adds an empty character''''''''''''' as the terminator of the string, so there are n pairs in the system. It must be noted that A and A are different. The former is a character constant, which only takes up one byte in memory; The latter is a string constant, which consists of characters'''''''''' a''' and'''''', and occupies two bytes of memory. However, the empty string constant'' actually contains an empty character'''''' \0''''''', which takes up the storage space of a character in memory. Second, the symbol constant symbol constant replaces the constant with the defined identifier. For some constants with long numbers, repeated occurrences or frequent modifications in programming, using symbolic constants has its unique advantages. When the values of these constants need to be changed during program debugging or transplantation, it is only necessary to modify the values replaced by the symbol constant macro at the beginning of the source program. If PI 3. 14 159 is often used in the program, it can be replaced by a symbolic constant by macro replacement command: define PI 3. 14 159 /*, and replace the constant by macro replacement command. In this way, the garden is always used in the program. In order to stand out, it is customary to use capital letters to form identifiers of symbol constants. I hope my answer will satisfy you ~!
Thanks ~!