Constant expression

Integer constants and real constants
1. Integer constants
In C language, integer constants have three
representations: decimal integer constants, octal integer constants and hexadecimal integer constants .

(1) Decimal integer constants
This constant can only appear in numbers from 0 to 9, and can have positive and negative signs. For example:
0 1 364 28 -34

(2) Octal integer constants
This constant is an octal number string starting with the number 0. The numbers are 0-7. For example:
0111 (decimal 73) 011 (decimal 9) 0123 (decimal 83)

(3) Hexadecimal integer constants
This constant is a hexadecimal number string starting with 0x or 0X. Each number can be a number from 0-9, a-f or A-
F or an English letter. For example:
0x11 (decimal 17) 0Xa5 (decimal 165) 0x5a (decimal 90) The
above three constants can be used in different occasions. In most occasions, decimal constants are used, but when writing
system programs, such as expressing addresses, octal or hexadecimal constants are commonly used.

Under normal circumstances, the compiler will distinguish whether the constant is of type int or long int based on the value of the constant. But in
some cases, it is necessary to clearly indicate whether it belongs to the long int type. At this time, you can append a letter l
or L to the integer constant to force it to be of type long int. For example, 4126l, 78l, 5L, etc.

2. Real constants
Real constants have two representations: one is in decimal form and the other is in exponential form. (1) Decimal decimal form The decimal decimal form is a decimal digit string containing a decimal point. Such real constants can have no digits before or after the decimal point, but they cannot have digits at the same time. For example: 3.14159, .89, 56.0, 78., -3.0, 0.0 (2) Exponential form The exponential form consists of two parts: decimal decimal form or decimal integer constant part and exponent part. The exponent part is e or E (equivalent to power base 10 in mathematics) followed by an integer order code (that is, a signed integer exponent). For example: 1e15 //represents the value 1×10^15

0.35e+1 // indicates the value 0.35×10^1
78e-1 // indicates the value 78×10^-1 The following is an incorrect real constant. e15 //The decimal fraction is missing 0.35e //The order code 78e-1.2 is missing //Not an integer order code

  1. Decimal decimal form. Composed of numbers and decimal points, there must be a decimal point. For example (123.) (123.0) (.123).
  2. Index form. Such as 123e3. There must be a number before the letter e (or E), and the exponent after the e must be an integer. 3. In the normalized exponential form, there is only one non-zero number before the decimal point. Such as 1.2345e8

Guess you like

Origin blog.csdn.net/weixin_52045928/article/details/112270123