Namespace
Varianti

sizeof operator

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Controllo del flusso
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dichiarazioni esecuzione condizionale
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterazione dichiarazioni
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Vai dichiarazioni
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Tipo alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della memoria
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
esplicito (C++11)
statico
Funzioni membro speciali
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
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.
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.

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.

[modifica] Spiegazione

1)
restituisce la dimensione in byte della rappresentazione di oggetti di type.
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.
2)
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.

[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.
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.
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.
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.
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.

[modifica] Parole chiave

sizeof

[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.

#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

[modifica] Vedi anche