zero initialization
Da cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Define o valor inicial de um objeto a zero
Original:
Sets the initial value of an object to zero
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.
Índice |
[editar] Sintaxe
static T object ;
|
(1) | ||||||||
int () ;
|
(2) | ||||||||
char array [ n ] = "";
|
(3) | ||||||||
[editar] Explicação
Zero inicialização é executada nas seguintes situações:
Original:
Zero initialization is performed in the following situations:
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.
1)
Para cada variável chamada com duração de armazenagem estática ou segmento local, antes de qualquer outra inicialização.
Original:
For every named variable with static or thread-local storage duration, before any other initialization.
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.
2)
Como parte do valor de inicialização seqüência para não-classe tipos e para os membros do Valor inicializados tipos de classes que não têm construtores.
Original:
As part of valor de inicialização sequence for non-class types and for members of value-initialized class types that have no constructors.
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.
3)
Quando uma matriz de caracteres é inicializado com uma string literal que é muito curto, o restante da matriz é inicializado com zero.
Original:
When a character array is initialized with a string literal that is too short, the remainder of the array is zero-initialized.
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.
Os efeitos de inicialização de zero são:
Original:
The effects of zero initialization are:
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.
- Se
T
é um tipo escalar, o valor inicial do objeto é o convertidos implicitamente de zero integrante constante paraT
.Original:IfT
is a scalar type, the object's initial value is the integral constant zero convertidos implicitamente toT
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se
T
é um tipo de classe não-união, todas as classes base e membros não-estáticos de dados são inicializado com zero, e todo estofamento é inicializado com zero bits. Os construtores, se houver, são ignorados.Original:IfT
is an non-union class type, all base classes and non-static data members are zero-initialized, and all padding is initialized to zero bits. The constructors, if any, are ignored.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se
T
é um tipo de união, o primeiro não-estático chamado membro de dados é inicializado com zero e todo estofamento é inicializado com zero bits.Original:IfT
is a union type, the first non-static named data member is zero-initialized and all padding is initialized to zero bits.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se
T
é tipo de matriz, cada elemento é inicializado com zeroOriginal:IfT
is array type, each element is zero-initializedThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se
T
é tipo de referência, nada é feito.Original:IfT
is reference type, nothing is done.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
[editar] Notas
As variáveis estáticas e segmento local é o primeiro zero-inicializado e então inicializado novamente como especificado no programa, por exemplo, estática função local é o primeiro zero-inicializado no arranque do programa, e então seu construtor é chamado quando a função é primeiro entrou. Se a declaração de uma estática não-classe não tem inicializador, então a inicialização padrão não faz nada, deixando o resultado do início de zero-inicialização sem modificações.
Original:
The static and thread-local variables are first zero-initialized and then initialized again as specified in the program, e.g. a function-local static is first zero-initialized at program startup, and then its constructor is called when the function is first entered. If the declaration of a non-class static has no initializer, then default initialization does nothing, leaving the result of the earlier zero-initialization unmodified.
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.
Um ponteiro inicializado com zero é o valor de ponteiro nulo do seu tipo, mesmo que o valor do ponteiro nulo não é zero integrante.
Original:
A zero-initialized pointer is the null pointer value of its type, even if the value of the null pointer is not integral zero.
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.
[editar] Exemplo
#include <string> double f[3]; // zero-initialized to three 0.0's int* p; // zero-initialized to null pointer value std::string s; // zero-initialized to indeterminate value // then default-initialized to "" int main(int argc, char* argv[]) { static int n = argc; // zero-initialized to 0 // then copy-initialized to argc delete p; // safe to delete a null pointer }