Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is a legal C constant and what is an illegal C constant? Please give a detailed definition and explanation.
What is a legal C constant and what is an illegal C constant? Please give a detailed definition and explanation.
Constants are fixed values and will not change during program execution. These fixed values are also called literal quantities.

Constants can be any basic data type, such as integer constants, floating-point constants, character constants or string literals, and there are also enumerated constants.

Constants are similar to regular variables, except that the values of constants cannot be modified after definition.

Integer constants can be decimal, octal or hexadecimal constants. Prefix specifies radix: 0X or 0x means hexadecimal, 0 means octal, and no prefix means decimal by default.

2 12? /*? Legal? */

2 15u/*? Legal? */

0xFeeL? /*? Legal? */

078? /*? Illegal: 8? Not an octal number? */

032UU/*? Illegal: Suffixes cannot be repeated? */Floating-point constant consists of integer part, decimal point, decimal part and exponent part. You can use decimal form or exponential form to represent floating-point constants.

When expressed in decimal form, it must include decimal point, exponent or both. When an exponential representation is used, it must include an integer part, a decimal part or both. Signed exponents are introduced with e or e.

3. 14 159/*? Legal? */

3 14 159E-5L/*? Legal? */

5 10E? /*? Illegal: Incomplete index? */

2 10f? /*? Illegal: No decimals or exponents? */

. e55? /*? Illegal: Missing integer or fraction? */Character constants are enclosed in single quotation marks. For example,' x' can be stored in? Charles? In a simple variable of type.

Character constants can be ordinary characters (such as' x'), escape sequences (such as' \t') or universal characters (such as' \u02C0'). In C, there are some specific characters that have special meanings when they are preceded by backslashes, which are used to represent, for example, line breaks (\n) or tabs (\t).

String literals or constants are enclosed in double quotes "". A string contains characters similar to character constants: ordinary characters, escape sequences and common characters. You can use spaces as separators to arrange long string constants.

In C, there are two simple ways to define constants: 1 and using? # Definition? Preprocessor; 2. use? const? Keywords: # Definition length 10.