Author: NCRE Research Group
Publisher:
Publish Date: 2003-02-12
Features: A constant is a value that cannot be changed during program execution. Constants have two representation forms: (1) Literal constants: The constant value can be determined from its literal form; (2) Symbolic constants: An identifier is used to represent a specific constant value, i.e., giving a name to a literal constant. For example, "pai equals 3.14159," where pai is a symbolic constant and 3.14159 is a literal constant; "LENGTH equals 50," where LENGTH is a symbolic constant and 50 is a literal constant.
1. Literal Constants
Literal constants include integer, floating-point, character, string, and logical types.
(1) Integer Constants
Integer constants have three representation forms:
① Decimal integers. For example, 123, -456, 0.
② Octal integers. Integers starting with 0 are octal numbers. For example, 0123 represents the octal number 123.
③ Hexadecimal integers. Integers starting with 0x or 0X are hexadecimal numbers. For example, 0x123 or 0X123 represents the hexadecimal number 123 (which equals the decimal number 291).
If a letter u or U is added after an integer constant, it represents an unsigned integer (unsigned int). For example, 123U or 123u is of type unsigned int.
If a letter L or l is added after an integer constant, it represents a long integer (long int). For example, 123L or 123l is of type long int.
(2) Floating-Point Constants
Floating-point constants have two representation forms:
① Decimal fractional form. Composed of digits and a decimal point, and a decimal point is required. For example, .123, 123., 123.0, 0.123, 0.0, etc.
② Exponential form. For example, 123e4 or 123E4 both represent 123 × 10^4.
Note that there must be digits before e (or E), and the exponent after e (or E) must be an integer. Forms like e4, 1.2e3.4, .e4, e, etc., are not valid exponential forms.
If no specification is provided, a floating-point constant represents a double-type data; to represent float-type data, a letter F or f must be added after the floating-point constant. For example, 1.23 is of type double, while 1.23f or 1.23F is of type float.
(3) Character Constants
A character constant is a single character enclosed in single quotes. For example, 'a', 'A', '?', '$', etc., are all character constants. Characters with control functions or used as special markers must be represented using escape sequences preceded by a backslash. For example, "\n" represents a newline character, "\t" represents a tab character, and "\" represents a single quote, etc. Table 2.2 on page 19 of the tutorial lists the commonly used character escape sequences in C.
National Computer Rank Examination Level 2 Preparation--C++ Language
📌 Related Posts
News
My vaginitis, how should it be treated?
2026-09-29
News
What are the possible reasons for menstrual irregularities?
2026-09-30
Literature
GB 50005-2003 - Timber Structure Design Code - (2005 Edition)
2026-10-05
Literature
Chinese Higher Vocational English Professional Education Theoretical Research
2026-10-05
Literature
Signal Processing
2026-10-07
Literature
New Concept Photoshop CS Tutorial
2026-10-07
Literature
PROJECT 2002 project management
2026-10-07
Literature
Software Technology Basics
2026-10-07