Home >Backend Development >C#.Net Tutorial >How to express numerical constants in C language
In C language, numeric constants can be represented as integers, floating point and character constants. Integer constants can be represented in decimal, octal, or hexadecimal, and can be signed or unsigned; floating-point constants can be represented in decimal or scientific notation; character constants are represented by a single character enclosed in single quotes.
Representation of numerical constants in C language
In C language, numerical constants can be represented as integers Constants, floating point constants and character constants.
Integer constants
Integer constants can be represented as signed or unsigned integers, and can be represented using decimal, octal, or hexadecimal notation. Signed integers use a minus sign (-) to represent negative values, while unsigned integers have no sign.
<code class="c">// 无符号十进制整数 unsigned int num1 = 100; // 有符号十进制整数 int num2 = -50; // 八进制整数 int num3 = 0777; // 十六进制整数 int num4 = 0xABCD;</code>
Floating point constants
Floating point constants are expressed as decimals or scientific notation. Decimal format consists of an integer part and a decimal part, separated by a decimal point (.). Scientific notation consists of a number multiplied by a power of 10.
<code class="c">// 小数浮点常量 float num1 = 3.14; // 科学记数法浮点常量 double num2 = 6.022e23;</code>
Character constants
Character constants are represented as a single character, enclosed in single quotes (').
<code class="c">// 字符常量 char ch = 'a';</code>
Note:
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!