Espacios de nombres
Variantes
Acciones

C++ Operator Precedence

De cppreference.com
< cpp‎ | language
 
 
Lenguaje C++
Temas generales
Control de flujo
Instrucciones de ejecución condicionales
Instrucciones de iteración (bucles)
Declaraciones de salto
Funciones
Declaración de funciones
Declaración de funciones lambda
Especificador inline
Especificación de excepciones (hasta C++20)
Especificador noexcept (C++11)
Excepciones
Espacios de nombres
Tipos
Especificadores
decltype (C++11)
auto (C++11)
alignas (C++11)
Especificadores de duración de almacenamiento
Inicialización
Expresiones
Operadores
Precedencia de operadores
Representaciones alternas
Literales
Booleanos - Enteros - De punto flotante
De carácter - De cadena - nullptr (C++11)
Definidos por el usuario (C++11)
Utilidades
Atributos (C++11)
Tipos
Declaración de typedef
Declaración de alias de tipo (C++11)
Conversiones
Conversiones implícitas - Conversiones explícitas
static_cast - dynamic_cast
const_cast - reinterpret_cast
Asignación de memoria
Clases
Propiedades de funciones específicas de la clase
Funciones miembro especiales
Plantillas
Misceláneos
 
La siguiente tabla muestra la precedencia y asociatividad de operadores de C + +. Los operadores se enumeran arriba a abajo, de mayor a menor precedencia .
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.
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
Al analizar una expresión, un operador que aparece en alguna fila será atado apretado (como si entre paréntesis) a sus argumentos que cualquier operador que aparece en una fila, más abajo. Por ejemplo, las expresiones std::cout<<a&b y *p++ se analizan como (std::cout<<a)&b y *(p++), y no como 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.
Los operadores que están en la misma célula (puede haber varias filas de operadores listados en una célula) se evalúan con la misma prioridad, en la dirección dada. Por ejemplo, la expresión a=b=c se analiza como a=(b=c), y no como (a=b)=c a causa de derecha a izquierda asociatividad .
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.
Precedencia de un operador no se ve afectado por la sobrecarga .
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.

[editar] Notas

La propia norma no especifica niveles de precedencia. Se derivan de la gramática .
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.
const_cast, static_cast, dynamic_cast, reinterpret_cast typeid y no se incluyen ya que nunca son ambiguas .
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.
Algunos de los operadores tienen ortografías alternativas (por ejemplo, para and &&, or para ||, not para !, etc) .
Original:
Some of the operators have ortografías alternativas (e.g., and for &&, or for ||, not for !, etc.).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Ver también

Orden de evaluación de los argumentos del operador en tiempo de ejecución .
Original:
Orden de evaluación 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.
Operadores comunes
Asignación Incremento/decremento Aritméticos Lógicos Comparación Acceso a miembro Otros

a = b
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b
a <=> b

a[b]
*a
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
? :

Operadores especiales

static_cast Convierte de un tipo a otro tipo relacionado
dynamic_cast Convierte dentro de jerarquías de herencia
const_cast Añade o suprime los calificadores const/volatile
reinterpret_cast Convierte un tipo a un tipo no relacionado
conversión estilo C Convierte un tipo a otro mediante una mezcla de static_cast, const_cast, y reinterpret_cast
new Crea objetos con duración de almacenamiento dinámica
delete Destruye objetos previamente creados por la expresión new y libera el área de memoria obtenida
sizeof Consulta el tamaño de un tipo
sizeof... Consulta el tamaño de un paquete de parámetros (desde C++11)
typeid Consulta la información de un tipo
noexcept Comprueba si una expresión puede lanzar una excepción (desde C++11)
alignof Consulta requisitos de alineación de un tipo (desde C++11)