C Language Learning Tutorial Chapter II-Data types, operators, expressions (iii)

Source: Internet
Author: User

Real-Type Quantity

Real constants

The real type is also called a floating-point type. Real constants are also called real numbers or floating-point numbers. In the C language, the real number is only decimal. It has two kinds of forms: decimal form exponential form
1. Decimal number Form
Made up of digital 0~ 9 and decimal points. For example: 0.0,.25,5.789,0.13,5.0,300.,-267.8230 and so on are valid real numbers.
2. Exponential form
Consists of a decimal number, a step code flag "E" or "E", and a step code (only integers, which can be signed). Its general form is a E n (A is decimal, n is a decimal integer) its value is a*10,n such as: 2.1E5 (equal to 2.1*10,5), 3.7E-2 (equal to 3.7*10,) -2*) 0.5E7 (equal to 0.5*10,7), -2.8E-2 (equal to -2.8*1 0,) -2*) The following is not a valid real number 345 (no decimal point) E7 (no digits before the order sign E)-5 (no order sign) 53.-e3 (minus position is not right) 2.7E (no order)
Standard C allows floating-point numbers to use suffixes. A suffix of "f" or "F" means that the number is a float. such as 356f and 356. is equivalent. Example 2.2 illustrates this situation:
void Main ()
{
printf ("%f\n%f\n", 356.,356f);
}
Void indicates that main does not return any value using printf display result end

Real-type variables

The real variables are divided into two types: single and double-precision,
Its type specifier is a float-precision specifier, double double-precision descriptor. In Turbo C, a single precision 4 byte (32-bit) memory space with a value range of 3.4e-38~3.4e+38 and only seven digits valid digits. The double is a 8-byte (64-bit) memory space with a value range of 1.7e-308~1.7e+308, which provides 16-digit valid digits.
The format and writing rules for the description of the real variable are the same as the integer type.
For example: float x,y; (X,y is a single-precision real-type quantity)
Double a,b,c; (A,b,c is a double-precision real-type quantity)
The real constant is not divided into single and double precision, and is treated as double.
void Main ()
{
float A;
Double b;
a=33333.33333;
b=33333.33333333333333;
printf ("%f\n%f\n", a,b);
}
This program illustrates the difference between float and double
A
b
a<---33333.33333
b<---33333.33333333333;;
Show program Results
This program illustrates the difference between float and double
float A;
Double b;
a=33333.33333;
b=33333.33333333333333; As you can see from this example, because a is a single-precision floating-point type, the number of significant digits is only seven digits. And the integer has accounted for five digits, so after the decimal two digits are invalid numbers. B is a double with a valid bit of 16 digits. But Turbo C stipulates a maximum of six digits after a decimal, and the remainder is rounded.
[Practice]//floatint a=32;
float B;
Double D;
b=12345678;
d=b*100;
D=d+a;
d=d+58.123456; ' Vtable
A,2,32
b,4,0.0
d,8,0.0
of Vtable
' Vupdate
1,32
2,0
3,0
2,12345678.00000
3,1234567800
3,1234567832
3,1234567890.123456
of Vupdate
of Practice
[Practice]//1int a=543;
float B;
B=123.123962+a;
b=b-100;
a=b; ' Vtable
a,2,543
b,4,0.0
of Vtable
' Vupdate
1,543
2,0.0
2,123.123962
2,23.123962
1,23
of Vupdate
of Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.