Typy wbudowane (C++)Built-in types (C++)
Typy wbudowane (zwane również typami podstawowymi) są określane przez Standard języka C++ i są wbudowane w kompilator.Built-in types (also called fundamental types) are specified by the C++ language standard and are built into the compiler. Wbudowane typy nie są zdefiniowane w żadnym pliku nagłówkowym.Built-in types aren't defined in any header file. Typy wbudowane są podzielone na trzy główne kategorie: Całka, zmiennoprzecinkowa i void.Built-in types are divided into three main categories: integral, floating-point, and void. Typy całkowite reprezentują liczby całkowite.Integral types represent whole numbers. Typy zmiennoprzecinkowe mogą określać wartości, które mogą mieć części ułamkowe.Floating-point types can specify values that may have fractional parts. Większość typów wbudowanych jest traktowana jako odrębne typy przez kompilator.Most built-in types are treated as distinct types by the compiler. Jednak niektóre typy są synonimami lub traktowane jako równoważne typy przez kompilator.However, some types are synonyms, or treated as equivalent types by the compiler.
Typ voidVoid type
void
Typ opisuje pusty zestaw wartości.The void
type describes an empty set of values. Nie można określić żadnej zmiennej typu void
.No variable of type void
can be specified. void
Typ jest używany głównie do deklarowania funkcji, które nie zwracają wartości ani do deklarowania wskaźników ogólnych do niewpisanych lub arbitralnie wpisanych danych.The void
type is used primarily to declare functions that return no values or to declare generic pointers to untyped or arbitrarily typed data. Każde wyrażenie może być jawnie konwertowane lub rzutowane na typ void
.Any expression can be explicitly converted or cast to type void
. Jednakże takie wyrażenia są ograniczone do następujących celów:However, such expressions are restricted to the following uses:
Instrukcja wyrażenia.An expression statement. (Aby uzyskać więcej informacji, zobacz Expressions).(For more information, see Expressions.)
Lewy operand operatora przecinka.The left operand of the comma operator. (Aby uzyskać więcej informacji, zobacz operator przecinka).(For more information, see Comma Operator.)
Drugi lub trzeci operand operatora warunkowego (
? :
).The second or third operand of the conditional operator (? :
). (Aby uzyskać więcej informacji, zobacz wyrażenia z operatorem warunkowym).(For more information, see Expressions with the Conditional Operator.)
std:: nullptr_tstd::nullptr_t
Słowo kluczowe nullptr
jest stałą wskaźnika o wartości null typu std::nullptr_t
, który jest konwertowany na dowolny nieprzetworzony typ wskaźnika.The keyword nullptr
is a null-pointer constant of type std::nullptr_t
, which is convertible to any raw pointer type. Aby uzyskać więcej informacji, zobacz nullptr
.For more information, see nullptr
.
Typ wartości logicznejBoolean type
bool
Typ może mieć wartości true
i false
.The bool
type can have values true
and false
. Rozmiar bool
typu jest specyficzny dla implementacji.The size of the bool
type is implementation-specific. Zobacz rozmiary typów wbudowanych dla szczegółów implementacji specyficznych dla firmy Microsoft.See Sizes of built-in types for Microsoft-specific implementation details.
Typy znakówCharacter types
char
Typ jest typem reprezentacji znaku, który efektywnie koduje elementy członkowskie podstawowego zestawu znaków wykonania.The char
type is a character representation type that efficiently encodes members of the basic execution character set. Kompilator języka C++ traktuje zmienne typu char
, signed char
i unsigned char
jako mające różne typy.The C++ compiler treats variables of type char
, signed char
, and unsigned char
as having different types.
Specyficzne dla firmy Microsoft: zmienne typu char
są podwyższane int
jako Jeśli signed char
Domyślnie, chyba że /J
jest używana opcja kompilacji.Microsoft-specific: Variables of type char
are promoted to int
as if from type signed char
by default, unless the /J
compilation option is used. W tym przypadku są one traktowane jako typ unsigned char
i są promowane do int
bez rozszerzenia znaku.In this case, they're treated as type unsigned char
and are promoted to int
without sign extension.
Zmienna typu wchar_t
jest typu szerokiego lub wielobajtowego.A variable of type wchar_t
is a wide-character or multibyte character type. Użyj L
prefiksu przed znakiem lub literałem ciągu, aby określić typ szerokich znaków.Use the L
prefix before a character or string literal to specify the wide-character type.
Specyficzne dla firmy Microsoft: Domyślnie wchar_t
jest typem natywnym, ale można użyć, /Zc:wchar_t-
Aby utworzyć wchar_t
element typedef dla unsigned short
.Microsoft-specific: By default, wchar_t
is a native type, but you can use /Zc:wchar_t-
to make wchar_t
a typedef for unsigned short
. __wchar_t
Typ jest synonimem specyficznym dla firmy Microsoft dla typu natywnego wchar_t
.The __wchar_t
type is a Microsoft-specific synonym for the native wchar_t
type.
char8_t
Typ jest używany dla reprezentacji znaków UTF-8.The char8_t
type is used for UTF-8 character representation. Ma taką samą reprezentację jak unsigned char
, ale jest traktowana jako odrębny typ przez kompilator.It has the same representation as unsigned char
, but is treated as a distinct type by the compiler. char8_t
Typ jest nowy w języku c++ 20.The char8_t
type is new in C++20. Specyficzne dla firmy Microsoft: użycie char8_t
wymaga /std:c++latest
opcji kompilatora.Microsoft-specific: use of char8_t
requires the /std:c++latest
compiler option.
char16_t
Typ jest używany dla reprezentacji znaków UTF-16.The char16_t
type is used for UTF-16 character representation. Musi być wystarczająco duży, aby reprezentować dowolną jednostkę kodu w formacie UTF-16.It must be large enough to represent any UTF-16 code unit. Jest on traktowany jako typ odrębny przez kompilator.It's treated as a distinct type by the compiler.
char32_t
Typ jest używany dla reprezentacji znaków UTF-32.The char32_t
type is used for UTF-32 character representation. Musi być wystarczająco duży, aby reprezentować dowolną jednostkę kodu w formacie UTF-32.It must be large enough to represent any UTF-32 code unit. Jest on traktowany jako typ odrębny przez kompilator.It's treated as a distinct type by the compiler.
Typy zmiennoprzecinkoweFloating-point types
Typy zmiennoprzecinkowe wykorzystują reprezentację IEEE-754, aby zapewnić przybliżenie wartości ułamkowych w szerokim zakresie wielkości.Floating-point types use an IEEE-754 representation to provide an approximation of fractional values over a wide range of magnitudes. Poniższa tabela zawiera listę typów zmiennoprzecinkowych w języku C++ i ograniczenia porównawcze dla rozmiaru typu zmiennoprzecinkowego.The following table lists the floating-point types in C++ and the comparative restrictions on floating-point type sizes. Ograniczenia te są wymagane przez standard C++ i są niezależne od implementacji firmy Microsoft.These restrictions are mandated by the C++ standard and are independent of the Microsoft implementation. Rozmiar bezwzględny wbudowanych typów zmiennoprzecinkowych nie jest określany w standardzie.The absolute size of built-in floating-point types isn't specified in the standard.
TypType | ZawartośćContents |
---|---|
float |
Typ float to najmniejszy typ zmiennoprzecinkowy w języku C++.Type float is the smallest floating point type in C++. |
double |
Typ double jest typem zmiennoprzecinkowym, który jest większy niż lub równy typ float , ale krótszy niż lub równy rozmiarowi typu long double .Type double is a floating point type that is larger than or equal to type float , but shorter than or equal to the size of type long double . |
long double |
Typ long double wskazuje typ zmiennoprzecinkowy, który jest większy niż lub równy typowi double .Type long double is a floating point type that is larger than or equal to type double . |
Specyficzne dla firmy Microsoft: reprezentacja long double
i double
jest identyczna.Microsoft-specific: The representation of long double
and double
is identical. Jednak long double
i double
są traktowane jako różne typy przez kompilator.However, long double
and double
are treated as distinct types by the compiler. Kompilator języka Microsoft C++ używa reprezentacji zmiennoprzecinkowych 4-i 8-bajtowych IEEE-754.The Microsoft C++ compiler uses the 4- and 8-byte IEEE-754 floating-point representations. Aby uzyskać więcej informacji, zobacz reprezentacja zmiennoprzecinkowa IEEE.For more information, see IEEE floating-point representation.
Typy całkowiteInteger types
int
Typ jest domyślnym Basic typu Integer.The int
type is the default basic integer type. Może reprezentować wszystkie liczby całkowite w zakresie określonym dla implementacji.It can represent all of the whole numbers over an implementation-specific range.
Reprezentacja liczby całkowitej ze znakiem jest taka, która może zawierać zarówno wartości dodatnie, jak i ujemne.A signed integer representation is one that can hold both positive and negative values. Jest ona używana domyślnie lub kiedy signed
słowo kluczowe modyfikatora jest obecne.It's used by default, or when the signed
modifier keyword is present. unsigned
Słowo kluczowe modyfikatora określa niepodpisany reprezentację, która może zawierać tylko wartości nieujemne.The unsigned
modifier keyword specifies an unsigned representation that can only hold non-negative values.
Modyfikator rozmiaru Określa szerokość w bitach używanej reprezentacji liczb całkowitych.A size modifier specifies the width in bits of the integer representation used. Język obsługuje short
long
modyfikatory, i long long
.The language supports short
, long
, and long long
modifiers. short
Typ musi mieć co najmniej 16 bitów.A short
type must be at least 16 bits wide. long
Typ musi mieć co najmniej 32 bitów.A long
type must be at least 32 bits wide. long long
Typ musi mieć co najmniej 64 bitów.A long long
type must be at least 64 bits wide. Standard określa relację rozmiaru między typami całkowitymi:The standard specifies a size relationship between the integral types:
1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
Implementacja musi zachować minimalne wymagania dotyczące rozmiaru i relację rozmiaru dla każdego typu.An implementation must maintain both the minimum size requirements and the size relationship for each type. Jednak rzeczywiste rozmiary mogą być różne w zależności od implementacji.However, the actual sizes can and do vary between implementations. Zobacz rozmiary typów wbudowanych dla szczegółów implementacji specyficznych dla firmy Microsoft.See Sizes of built-in types for Microsoft-specific implementation details.
int
Słowo kluczowe może zostać pominięte signed
, jeśli unsigned
określono modyfikatory, lub rozmiaru.The int
keyword may be omitted when signed
, unsigned
, or size modifiers are specified. Modyfikatory i int
typy, jeśli istnieją, mogą pojawiać się w dowolnej kolejności.The modifiers and int
type, if present, may appear in any order. Na przykład, short unsigned
i unsigned int short
odwołują się do tego samego typu.For example, short unsigned
and unsigned int short
refer to the same type.
Synonimy typu IntegerInteger type synonyms
Następujące grupy typów są uznawane za synonimy przez kompilator:The following groups of types are considered synonyms by the compiler:
short
,short int
,signed short
,signed short int
short
,short int
,signed short
,signed short int
unsigned short
,unsigned short int
unsigned short
,unsigned short int
int
,signed
,signed int
int
,signed
,signed int
unsigned
,unsigned int
unsigned
,unsigned int
long
,long int
,signed long
,signed long int
long
,long int
,signed long
,signed long int
unsigned long
,unsigned long int
unsigned long
,unsigned long int
long long
,long long int
,signed long long
,signed long long int
long long
,long long int
,signed long long
,signed long long int
unsigned long long
,unsigned long long int
unsigned long long
,unsigned long long int
Typy liczb całkowitych specyficznych dla firmy Microsoft obejmują __int8
określone __int16
typy,, __int32
i __int64
.Microsoft-specific integer types include the specific-width __int8
, __int16
, __int32
, and __int64
types. Te typy mogą używać signed
unsigned
modyfikatorów i.These types may use the signed
and unsigned
modifiers. __int8
Typ danych jest synonimem typu char
, __int16
jest synonimem typu short
, __int32
jest synonimem typu int
i __int64
jest synonimem typu long long
.The __int8
data type is synonymous with type char
, __int16
is synonymous with type short
, __int32
is synonymous with type int
, and __int64
is synonymous with type long long
.
Rozmiary typów wbudowanychSizes of built-in types
Większość typów wbudowanych ma rozmiary zdefiniowane przez implementację.Most built-in types have implementation-defined sizes. W poniższej tabeli przedstawiono ilość pamięci wymaganej dla wbudowanych typów w programie Microsoft C++.The following table lists the amount of storage required for built-in types in Microsoft C++. W szczególności program long
ma 4 bajty nawet w 64-bitowych systemach operacyjnych.In particular, long
is 4 bytes even on 64-bit operating systems.
TypType | RozmiarSize |
---|---|
bool , char , char8_t , unsigned char , signed char , __int8 bool , char , char8_t , unsigned char , signed char , __int8 |
1 bajt1 byte |
char16_t , __int16 , short , unsigned short , wchar_t , __wchar_t char16_t , __int16 , short , unsigned short , wchar_t , __wchar_t |
2 bajty2 bytes |
char32_t , float , __int32 , int , unsigned int , long , unsigned long char32_t , float , __int32 , int , unsigned int , long , unsigned long |
4 bajty4 bytes |
double , __int64 , long double , long long , unsigned long long double , __int64 , long double , long long , unsigned long long |
8 bajtów8 bytes |
Zobacz zakresy typów danych , aby uzyskać podsumowanie zakresu wartości poszczególnych typów.See Data type ranges for a summary of the range of values of each type.
Aby uzyskać więcej informacji na temat konwersji typów, zobacz Konwersje standardowe.For more information about type conversion, see Standard conversions.