In C language, legal constants must: have a clear type: integer, floating point number, or character. Value is valid: within type range. No side effects: the value does not depend on program execution. Representations include: integers, floating point, characters, string constants, and escape sequences.
What are legal constants in C language?
In C language, constants refer to values that remain unchanged while the program is running. Unlike variables, constants cannot be reassigned after they are defined.
Legitimate C language constants must meet the following requirements:
Representation form: Constants can use the following representation forms:
For example, the following are some legal C language constants:
<code class="c">int my_age = 25; // 整型常量 float pi = 3.14; // 浮点常量 char letter = 'A'; // 字符常量 const char* greeting = "Hello World!"; // 字符串常量</code>
The above is the detailed content of What are legal constants in C language?. For more information, please follow other related articles on the PHP Chinese website!