Espaços nominais
Variantes
Acções

sizeof operator

Da cppreference.com
< cpp‎ | language

 
 
Linguagem C++
Tópicos gerais
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.
Controle de fluxo
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.
Declarações execução condicional
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.
Instruções de iteração
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.
Ir declarações
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.
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaração da função
lambda declaração da função
modelo de função
linha especificador
especificações de exceção (obsoleta)
noexcept especificador (C++11)
Exceções
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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)
Especificadores
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 especificadores
armazenamento duração especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialização
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literais
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressões
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representações alternativas
Utilitários
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipos
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 de alias declaração (C++11)
atributos (C++11)
Conversões
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversões implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Elenco C-estilo e funcional
Alocação de memória
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.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classe propriedades específicas de função
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.
Funções membro especiais
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.
Modelos
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
modelo de classe
modelo de função
especialização de modelo
pacotes de parâmetros (C++11)
Diversos
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Assembly embutido
 
Consultas tamanho do objeto ou 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.
Utilizado quando o tamanho real do objeto deve ser conhecido
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.

Índice

[editar] Sintaxe

sizeof( type )
sizeof expression None
Ambas as versões retornar uma constante de std::size_t tipo.
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.

[editar] Explicação

1)
retorna o tamanho em bytes da representação de objeto 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)
retorna o tamanho em bytes da representação de objeto do tipo, que seriam devolvidos por expression, se avaliados.
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.

[editar] Notas

sizeof(char), sizeof(signed char) e sizeof(unsigned char) sempre voltar 1, independentemente do valor 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 não pode ser usado com os tipos de função, tipos incompletos, ou bit de campo-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.
Quando aplicado a um tipo de referência, o resultado é o tamanho do tipo referenciado.
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 aplicado a um tipo de classe, o resultado é o tamanho de um objecto da classe mais qualquer acolchoamento adicional exigido para colocar tal objeto em uma matriz.
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 aplicado a um tipo de classe vazia, sempre retorna 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.

[editar] Palavras-chave

sizeof

[editar] Exemplo

A saída de exemplo corresponde a um sistema de 64 bits com os ponteiros de 32 bits e 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';
}

Saída:

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

[editar] Veja também