sizeof operator
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Dimensione query dell'oggetto o del tipo
Original:
Queries size of the object or type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Usato quando la dimensione reale dell'oggetto deve essere nota
Original:
Used when actual size of the object must be known
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica] Sintassi
sizeof( type )
|
|||||||||
sizeof expression None
|
|||||||||
Entrambe le versioni restituire una costante di tipo std::size_t.
Original:
Both versions return a constant of type std::size_t.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Spiegazione
1)restituisce la dimensione in byte della rappresentazione di oggetti di type.
2) Original:
returns size in bytes of the object representation of type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
restituisce la dimensione in byte della rappresentazione oggetto del tipo, che sarebbe restituito da expression, se valutata.
Original:
returns size in bytes of the object representation of the type, that would be returned by expression, if evaluated.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Note
sizeof(char), sizeof(signed char) e sizeof(unsigned char) sempre tornare 1, indipendentemente dal valore di CHAR_BIT.
Original:
sizeof(char), sizeof(signed char), and sizeof(unsigned char) always return 1, regardless of the value of CHAR_BIT.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
sizeof non può essere utilizzato con diversi tipi di funzione, tipi incompleti o bit-field lvalue.
Original:
sizeof cannot be used with function types, incomplete types, or bit-field lvalues.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Quando applicato ad un tipo di riferimento, il risultato è la dimensione del tipo indicato.
Original:
When applied to a reference type, the result is the size of the referenced type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Quando applicato ad un tipo di classe, il risultato è la dimensione di un oggetto di tale classe più qualsiasi imbottitura supplementare richiesto per collocare tale oggetto in un array.
Original:
When applied to a class type, the result is the size of an object of that class plus any additional padding required to place such object in an array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Quando viene applicato a un tipo di classe vuota, restituisce sempre 1.
Original:
When applied to an empty class type, always returns 1.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Parole chiave
[modifica] Esempio
L'output di esempio corrisponde a un sistema con puntatori a 64 bit e 32-bit int .
Original:
The example output corresponds to a system with 64-bit pointers and 32-bit int.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> struct Empty {}; struct Bit {unsigned bit:1; }; int main() { Empty e; Bit b; std::cout << "size of empty class: " << sizeof e << '\n' << "size of pointer : " << sizeof &e << '\n' // << "size of function: " << sizeof(void()) << '\n' // compile error // << "size of incomplete type: " << sizeof(int[]) << '\n' // compile error // << "size of bit field: " << sizeof b.bit << '\n' // compile error << "size of array of 10 int: " << sizeof(int[10]) << '\n'; }
Output:
size of empty class: 1 size of pointer : 8 size of array of 10 int: 40