Home  >  Article  >  Backend Development  >  How to express numerical constants in C language

How to express numerical constants in C language

下次还敢
下次还敢Original
2024-05-02 19:45:57522browse

Numeric constants in C language have the following representation methods: decimal integer octal integer hexadecimal integer decimal floating point number scientific notation character constant boolean constant

How to express numerical constants in C language

The representation of numeric constants in C language

Numeric constants refer to values ​​directly expressed in the program and will not change during program execution. . Numeric constants in C language have the following representation methods:

  • Integer constant: represents an integer, which can be decimal, octal or hexadecimal. Decimal integers have no prefix, octal integers are prefixed with 0, and hexadecimal integers are prefixed with 0x or 0X. For example:
<code class="c">10 // 十进制整数
012 // 八进制整数
0x10 // 十六进制整数</code>
  • Floating point constant: Represents a floating point number, which can be decimal or scientific notation. Decimal floating point numbers use a decimal point to separate the integer and fractional parts, and scientific notation uses e or E to represent powers of 10. For example:
<code class="c">3.14 // 十进制浮点数
1.6e5 // 科学记数法</code>
  • Character constant : represents a single character, surrounded by single quotes. For example:
<code class="c">'a' // 字符 'a'</code>
  • Boolean constant: represents the Boolean value true or false, represented by 1 and 0 respectively. For example:
<code class="c">true // 布尔值 true
false // 布尔值 false</code>

It should be noted that once a numeric constant in C language is declared, its type can no longer be changed. For example, if you assign a decimal integer to a floating-point variable, the decimal integer is implicitly converted to a floating-point number.

The above is the detailed content of How to express numerical constants in C language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn