Home > Backend Development > C#.Net Tutorial > What are the correct representation methods of C language constants?

What are the correct representation methods of C language constants?

angryTom
Release: 2020-03-09 15:31:22
Original
41594 people have browsed it

What are the correct representation methods of C language constants?

What are the correct representation methods of C language constants

Numeric constants in C language can be simply divided into the following two types of integer constants And floating point number constants:

1. Integer constants such as 6, 27, -299

In C language, integer constants are divided into decimal integer constants, There are three representation forms: octal integer constant and hexadecimal integer constant.

Recommended learning: c language video tutorial

(1) Decimal integer constant

This kind of constant can only appear Numbers from 0 to 9, and can have positive or negative signs. For example:

0 1 364 28 -34
Copy after login

(2) Octal integer constant

This kind of constant is an octal number string starting with the number 0. The numbers are 0 to 7. For example:

0111(十进制 73) 011(十进制 9) 0123(十进制 83)
Copy after login

(3) Hexadecimal integer constant

This kind of constant is a hexadecimal number string starting with 0x or 0X. Each number can be a number or English letter from 0 to 9, a to f, or A to F. For example:

0x11(十进制 17) 0Xa5(十进制 165) 0x5a(十进制 90)
Copy after login

2. Floating-point constants such as 5.43, -2.3, 5.67f

Real-type constants have two representation forms: one is decimal form, The other is the exponential form.

(1) Decimal format

The decimal format is a decimal number string containing a decimal point.

This type of real constant can have no digits before or after the decimal point, but not at the same time. For example:

3.14159, .89, 56.0, 78., -3.0, 0.0
Copy after login

(2) Exponential form

The format of the exponential form consists of two parts: decimal fractional form or decimal integer constant part and exponent part.

The exponent part is e or E (equivalent to the base 10 of a power in mathematics) followed by an integer exponent (that is, a signed integer exponent). For example:

1e15 //表示数值 1×10
15
0.35e+1 //表示数值 0.35×10
1
78e-1 //表示数值 78×10
-1
Copy after login

The following is an incorrect real constant.

e15 //缺少十进制小数部分
0.35e //缺少阶码
78e-1.2 //不是整数阶码
Copy after login

For more C languageIntroduction to Programming Tutorial, please pay attention to the PHP Chinese website!

The above is the detailed content of What are the correct representation methods of C language constants?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template