C++ Operator Precedence
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. |
La seguente tabella elenca le priorità e l'associatività degli operatori del C + +. Gli operatori sono elencati dall'alto verso il basso, in ordine decrescente la precedenza.
Original:
The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.
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.
Precedence | Operator | Description | Associativity |
---|---|---|---|
1 | ::
|
Scope resolution | Left-to-right |
2 | ++ --
|
Suffix/postfix increment and decrement | |
()
|
Function call | ||
[]
|
Array subscripting | ||
.
|
Element selection by reference | ||
−>
|
Element selection through pointer | ||
3 | ++ --
|
Prefix increment and decrement | Right-to-left |
+ −
|
Unary plus and minus | ||
! ~
|
Logical NOT and bitwise NOT | ||
(type)
|
Type cast | ||
*
|
Indirection (dereference) | ||
&
|
Address-of | ||
sizeof
|
Size-of | ||
new , new[]
|
Dynamic memory allocation | ||
delete , delete[]
|
Dynamic memory deallocation | ||
4 | .* ->*
|
Pointer to member | Left-to-right |
5 | * / %
|
Multiplication, division, and remainder | |
6 | + −
|
Addition and subtraction | |
7 | << >>
|
Bitwise left shift and right shift | |
8 | < <=
|
For relational operators < and ≤ respectively | |
> >=
|
For relational operators > and ≥ respectively | ||
9 | == !=
|
For relational = and ≠ respectively | |
10 | &
|
Bitwise AND | |
11 | ^
|
Bitwise XOR (exclusive or) | |
12 | |
|
Bitwise OR (inclusive or) | |
13 | &&
|
Logical AND | |
14 | ||
|
Logical OR | |
15 | ?:
|
Ternary conditional | Right-to-left |
=
|
Direct assignment (provided by default for C++ classes) | ||
+= −=
|
Assignment by sum and difference | ||
*= /= %=
|
Assignment by product, quotient, and remainder | ||
<<= >>=
|
Assignment by bitwise left shift and right shift | ||
&= ^= |=
|
Assignment by bitwise AND, XOR, and OR | ||
16 | throw
|
Throw operator (for exceptions) | |
17 | ,
|
Comma | Left-to-right |
Durante l'analisi un'espressione, un operatore che è quotata su qualche riga sarà legato più stretto (come se tra parentesi) per i suoi argomenti di qualsiasi operatore che è elencato in una riga più sotto di esso. Ad esempio, le espressioni e std::cout<<a&b *p++ vengono analizzati come (std::cout<<a)&b e *(p++), e non come std::cout<<(a&b) o (*p)++.
Original:
When parsing an expression, an operator which is listed on some row will be bound tighter (as if by parentheses) to its arguments than any operator that is listed on a row further below it. For example, the expressions std::cout<<a&b and *p++ are parsed as (std::cout<<a)&b and *(p++), and not as std::cout<<(a&b) or (*p)++.
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.
Operatori che si trovano nella stessa cella (ci possono essere molte file di operatori elencati in una cella) vengono valutate con la stessa priorità, nella direzione data. Ad esempio, l'espressione a=b=c viene analizzato come a=(b=c), e non come causa di (a=b)=c da destra a sinistra associatività.
Original:
Operators that are in the same cell (there may be several rows of operators listed in a cell) are evaluated with the same precedence, in the given direction. For example, the expression a=b=c is parsed as a=(b=c), and not as (a=b)=c because of right-to-left associativity.
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.
Precedenza di un operatore non è influenzato da sovraccarico.
Original:
An operator's precedence is unaffected by overloading.
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
La stessa norma non specifica i livelli di precedenza. Esse derivano dalla grammatica.
Original:
The standard itself doesn't specify precedence levels. They are derived from the grammar.
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.
const_cast, static_cast, dynamic_cast, reinterpret_cast typeid e non sono inclusi in quanto non sono mai ambigui.
Original:
const_cast, static_cast, dynamic_cast, reinterpret_cast and typeid are not included since they are never ambiguous.
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.
Alcuni operatori hanno ortografie alternative (ad esempio, per and
&&
, or per ||
, not per !
, ecc).Original:
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] Vedi anche
Ordine di valutazione di argomenti dell'operatore in fase di esecuzione.
Original:
Ordine di valutazione of operator arguments at run time.
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.
Common operators | ||||||
---|---|---|---|---|---|---|
assegnazione | incrementNJdecrement | aritmetica | logico | confronto | memberNJaccess | altra |
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
Special operators | ||||||
static_cast converte un tipo a un altro
tipo compatibile Original: static_cast converts one type to another compatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. dynamic_cast converte classe virtuale di base per class
derivato Original: dynamic_cast converts virtual base class to derived class The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. const_cast converte il tipo di tipo compatibile con diversi cv qualifiers
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. reinterpret_cast converte tipo type
incompatibile Original: reinterpret_cast converts type to incompatible type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. new alloca memory
Original: new allocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. delete dealloca memory
Original: delete deallocates memory The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof interroga la dimensione di un type
Original: sizeof queries the size of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. sizeof... interroga le dimensioni di un parametro confezione (dal C++11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. typeid interroga le informazioni sul tipo di una type
Original: typeid queries the type information of a type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. noexcept controlla se un'espressione può lanciare una (dal C++11)
un'eccezione Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. alignof query requisiti di allineamento di un (dal C++11) tipo
Original: alignof queries alignment requirements of a type (dal C++11) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |