Double Floating Point ใช้สำหรับเก็บข้อมูลประเภทตัวเลขทศนิยม โดยมีพื้นที่การเก็บมากกว่าตัวแปร float สองเท่า Show
เราสามารถใช้คำสั่งด้านล่างนี้ในการกำหนดเพิ่มลดขนาด(Size)และกำหนดช่วงข้อมูล(Range) ในพื้นที่หน่วยความจำและการรับข้อมูลสำหรับเก็บค่าตัวแปร
long ใช้สำหรับกำหนดขนาดตัวแปร int ให้ใช้พื้นที่เพิ่มขึ้นจาก 4 bytes เป็น 8 bytes เหมาะกับข้อมูลตัวเลขที่ไม่เยอะมาก (See also type for type system overview and the list of type-related utilities that are provided by the C++ library) Contents[edit] Void typevoid — type with an empty set of values. It is an incomplete type that cannot be completed (consequently, objects of type void are disallowed). There are no arrays of void, nor references to void. However, and functions returning type void (procedures in other languages) are permitted. [edit] std::nullptr_t (since C++11)typedef decltype(nullptr) nullptr_t; (since C++11) std::nullptr_t is the type of the null pointer literal, sizeof(std::nullptr_t) is equal to sizeof(void*). [edit] Data modelsThe choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance: 32 bit systems:
64 bit systems:
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. UNICOS on Cray). [edit] Integer types[edit] Standard integer typesint — basic integer type. The keyword int may be omitted if any of the modifiers listed below are used. If no length modifiers are present, it's guaranteed to have a width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits (see below). [edit] ModifiersModifies the basic integer type. Can be mixed in any order. Only one of each group can be present in type name.
Note: as with all type specifiers, any order is permitted: unsigned long long int and long int unsigned long name the same type. [edit] PropertiesThe following table summarizes all available integer types and their properties in various common data models: Type specifier Equivalent type Width in bits by data model C++ standard LP32 ILP32 LLP64 LP64 signed char signed char at least 8 8 8 8 8 unsigned char unsigned char short short int at least 16 16 16 16 16 short int signed short signed short int unsigned short unsigned short int unsigned short int int int at least 16 16 32 32 32 signed signed int unsigned unsigned int unsigned int long long int at least 32 32 32 32 64 long int signed long signed long int unsigned long unsigned long int unsigned long int long long long long int (C++11) at least 64 64 64 64 64 long long int signed long long signed long long int unsigned long long unsigned long long int (C++11) unsigned long long int Note: integer arithmetic is defined differently for the signed and unsigned integer types. See arithmetic operators, in particular . std::size_t is the unsigned integer type of the result of the [edit] Extended integer types (since C++11)The extended integer types are implementation-defined. Note that fixed width integer types are typically aliases of the standard integer types. [edit] Boolean typebool — type, capable of holding one of the two values: [edit] Character typessigned char — type for signed character representation.unsigned char — type for unsigned character representation. Also used to inspect object representations (raw memory).char — type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either signed char or unsigned char, but is always a distinct type). Multibyte characters strings use this type to represent code units. For every value of type unsigned char in range Besides the minimal bit counts, the C++ Standard guarantees that 1 \== sizeof(char) ≤ sizeof(short) ≤ sizeof(int) ≤ sizeof(long) ≤ sizeof(long long). Note: this allows the extreme case in which bytes are sized 64 bits, all types (including char) are 64 bits wide, and [edit] Floating-point types[edit] Standard floating-point typesThe following three types and their cv-qualified versions are collectively called standard floating-point types. float — single precision floating-point type. Matches IEEE-754 binary32 format if supported.double — double precision floating-point type. Matches IEEE-754 binary64 format if supported.long double — extended precision floating-point type. Matches IEEE-754 binary128 format if supported, otherwise matches IEEE-754 binary64-extended format if supported, otherwise matches some non-IEEE-754 extended floating-point format as long as its precision is better than binary64 and range is at least as good as binary64, otherwise matches IEEE-754 binary64 format.
[edit] Extended floating-point types (since C++23)The extended floating-point types are implementation-defined. They may include fixed width floating-point types. [edit] PropertiesFloating-point types may support special values:
Real floating-point numbers may be used with arithmetic operators +, -, /, and * as well as various mathematical functions from <cmath>. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in math errhandling. Floating-point expressions may have greater range and precision than indicated by their types, see FLT_EVAL_METHOD. Floating-point expressions may also be contracted, that is, calculated as if all intermediate values have infinite range and precision, see . Standard C++ does not restrict the accuracy of floating-point operations. Some operations on floating-point numbers are affected by and modify the state of the floating-point environment (most notably, the rounding direction). Implicit conversions are defined between real floating types and integer types. See and std::numeric_limits for additional details, limits, and properties of the floating-point types. [edit] Range of valuesThe following table provides a reference for the limits of common numeric representations. Prior to C++20, the C++ Standard allowed any signed integer representation, and the minimum guaranteed range of N-bit signed integers was from -(2N-1 -1) to +2N-1 -1 (e.g. −127 to 127 for a signed 8-bit type), which corresponds to the limits of ones' complement or . However, all C++ compilers use two's complement representation, and as of C++20, it is the only representation allowed by the standard, with the guaranteed range from -2N-1 to +2N-1 -1 (e.g. −128 to 127 for a signed 8-bit type). 8-bit ones' complement and sign-and-magnitude representations for char have been disallowed since C++11 (via the resolution of CWG issue 1759), because a UTF-8 code unit of value 0x80 used in a UTF-8 string literal must be storable in a char type object. The range for a floating-point type `sizeof`0 is defined as follows:
Since negative and positive infinity are representable in ISO/IEC/IEEE 60559 formats, all real numbers lie within the range of representable values of a floating-point type adhering to ISO/IEC/IEEE 60559. Type Size in bits Format Value range Approximate Exact character 8 signed −128 to 127 unsigned 0 to 255 16 UTF-16 0 to 65535 32 UTF-32 0 to 1114111 (0x10ffff) integer 16 signed ± 3.27 · 104 −32768 to 32767 unsigned 0 to 6.55 · 104 0 to 65535 32 signed ± 2.14 · 109 −2,147,483,648 to 2,147,483,647 unsigned 0 to 4.29 · 109 0 to 4,294,967,295 64 signed ± 9.22 · 1018 −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned 0 to 1.84 · 1019 0 to 18,446,744,073,709,551,615 binary floating point 32 IEEE-754
64 IEEE-754
80 x86
128 IEEE-754
Note: actual (as opposed to guaranteed minimal) limits on the values representable by these types are available in C numeric limits interface and std::numeric_limits. [edit] NotesFeature-test macro ValueStdFeature200704L (C++11)New character types (char16_t and char32_t)201811L (C++20) char8_t 202207L (C++23) char8_t compatibility and portability fix ( from UTF-8 string literals) [edit] Keywordsvoid, bool, true, false, char, wchar_t, char8_t, (since C++20) char16_t, char32_t, (since C++11)int, short, long, signed, unsigned, float, double [edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards. ตัวแปร unsigned long เป็นตัวแปรประเภทใด
หน่วยที่ 3 ข้อมูลพื้นฐานและตัวดำเนินการ : การโปรแกรมเบื้องต้นwbi.ohonline.in.th › unit3_1null Boolean มีขนาดและขอบเขตเท่าใด2.2 ชนิดตรรกะ ชนิดตรรกะ (boolean type) เป็นข้อมูลเลขจำนวนเต็มที่ประกอบด้วยค่าที่เป็นไปได้ 2 ค่า คือ false และ true ซึ่งเก็บค่าจำนวนเต็ม 0 และ 1 ตามลำดับ ข้อมูลชนิดตรรกะในภาษา C++ มาตรฐาน ได้แก่ ข้อมูลชนิด bool. ตัวอย่าง 2.1 ตัวแปรตรรกะ Float มีกี่ไบต์4. float เป็นตัวแปรที่ใช้เก็บข้อมูลที่เป็นเลขทศนิยม โดยจะเก็บอยู่ในรูป a.b x 10e ใช้ พื้นที่ในการเก็บ 4 ไบต์ มีค่าระหว่าง 3.4E-38 ถึง 3.4E+38 หรือ แสดงเป็น เลขทศนิยมได้ไม่เกิน 6 ต าแหน่ง ตัวอย่างตัวแปรชนิดนี้ เช่น 10.625 -6.67. INT ใช้กี่ไบต์ในบทความนี้. |