Espaces de noms
Variantes
Affichages
Actions

sizeof operator

De cppreference.com
< cpp‎ | language

 
 
Langage C++
Sujets généraux
Contrôle de flux
Instructions conditionnelles
Instructions d'itération
Instructions de saut
Fonctions
déclaration de fonction
expression lambda
fonction générique
spécificateur inline
spécification d'exception (obsolète)
spécificateur noexcept (C++11)
Exceptions
Espaces de noms
Types
spécificateur decltype (C++11)
Qualificatifs
qualificatifs const et volatile
qualificatifs de stockage
qualificatif constexpr (C++11)
qualificatif auto (C++11)
qualificatif alignas (C++11)
Initialisation
Littéraux
Expressions
opérateurs alternatifs
Utilitaires
Types
déclaration typedef
déclaration d'alias de type (C++11)
attributs (C++11)
Jette
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversions implicites
conversion const_cast
conversion static_cast
conversion dynamic_cast
conversion reinterpret_cast
conversions style C et style fonction
Allocation de mémoire
Classes
Qualificatifs spécifiques aux membres de classe
Fonctions membres spéciales
Modèles
classes génériques
fonctions génériques
spécialisation de modèles
paquets de paramètres (C++11)
Divers
Assembleur
 
La taille des requêtes de l'objet ou de type
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.
Utilisé lorsque la taille réelle de l'objet doit être connue
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.

Sommaire

[modifier] Syntaxe

sizeof( type )
sizeof expression None
Les deux versions renvoient une constante de std::size_t type .
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.

[modifier] Explication

1)
taille en octets rendement de la représentation de l'objet de 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)
taille en octets rendement de la représentation de l'objet du type, qui doit être retourné par expression, en cas d'évaluation .
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.

[modifier] Notes

sizeof(char), sizeof(signed char), et sizeof(unsigned char) toujours revenir 1, quelle que soit la valeur de 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 ne peut pas être utilisée avec les types de fonctions, des types incomplets ou peu-terrain lvalues ​​.
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.
Lorsqu'il est appliqué à un type référence, le résultat est la taille du type référencé .
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.
Lorsqu'il est appliqué à un type de classe, le résultat est la taille d'un objet de cette classe ainsi que tout rembourrage supplémentaire nécessaire pour placer un tel objet dans un tableau .
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.
Lorsqu'il est appliqué à un type de classe vide, renvoie toujours 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.

[modifier] Mots-clés

sizeof

[modifier] Exemple

L'exemple de sortie correspond à un système avec des pointeurs 64 bits et 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';
}

Résultat :

size of empty class: 1
size of pointer : 8
size of array of 10 int: 40

[modifier] Voir aussi