Espacios de nombres
Variantes
Acciones

Arithmetic operators

De cppreference.com
< cpp‎ | language

 
 
Lenguaje C++
Los temas generales
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.
Control de flujo
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.
Sentencias condicionales ejecución
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.
Instrucciones de iteración
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 declaraciones
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.
Funciones
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
declaración de la función
lambda declaración de la función
función de plantilla
especificador inline
especificaciones de excepción (obsoleto)
noexcept especificador (C++11)
Excepciones
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los espacios de nombres
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)
Los 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
almacenamiento duración especificadores
constexpr especificador (C++11)
auto especificador (C++11)
alignas especificador (C++11)
Inicialización
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Los literales
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expresiones
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
representaciones alternativas
Utilidades
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
alias de tipo de declaración (C++11)
atributos (C++11)
Lanza
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversiones implícitas
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-cast estilo y funcional
De asignación de memoria
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.
Clases
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Clase propiedades específicas de la función
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.
Funciones especiales miembro
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.
Plantillas
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clase de plantilla
función de plantilla
plantilla de especialización
paquetes de parámetros (C++11)
Varios
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaje en línea
 
Devuelve el resultado de la operación aritmética específica .
Original:
Returns the result of specific arithmetic operation.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operator name Syntax Over​load​able Prototype examples (for class T)
Inside class definition Outside class definition
unary plus +a Yes T T::operator+() const; T operator+(const T &a);
unary minus -a Yes T T::operator-() const; T operator-(const T &a);
addition a + b Yes T T::operator+(const T2 &b) const; T operator+(const T &a, const T2 &b);
subtraction a - b Yes T T::operator-(const T2 &b) const; T operator-(const T &a, const T2 &b);
multiplication a * b Yes T T::operator*(const T2 &b) const; T operator*(const T &a, const T2 &b);
division a / b Yes T T::operator/(const T2 &b) const; T operator/(const T &a, const T2 &b);
modulo a % b Yes T T::operator%(const T2 &b) const; T operator%(const T &a, const T2 &b);
bitwise NOT ~a Yes T T::operator~() const; T operator~(const T &a);
bitwise AND a & b Yes T T::operator&(const T2 &b) const; T operator&(const T &a, const T2 &b);
bitwise OR a | b Yes T T::operator|(const T2 &b) const; T operator|(const T &a, const T2 &b);
bitwise XOR a ^ b Yes T T::operator^(const T2 &b) const; T operator^(const T &a, const T2 &b);
bitwise left shift a << b Yes T T::operator<<(const T2 &b) const; T operator<<(const T &a, const T2 &b);
bitwise right shift a >> b Yes T T::operator>>(const T2 &b) const; T operator>>(const T &a, const T2 &b);
'Notas'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Todos los valores integrados operadores de retorno, y más definidos por el usuario sobrecargas también devuelven valores de modo que los operadores definidos por el usuario se pueden utilizar de la misma manera como la empotrados. Sin embargo, en una definida por el usuario sobrecarga del operador, cualquier tipo puede ser utilizado como tipo de retorno (incluyendo void). En particular inserción corriente y sobrecargas de corriente de extracción operator<< y operator>> retorno T& .
    Original:
    All built-in operators return values, and most user-defined overloads also return values so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (including void). In particular, stream insertion and stream extraction overloads of operator<< and operator>> return T&.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • T2 puede ser cualquier tipo incluyendo T
    Original:
    T2 can be any type including T
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Explicación

Todos los operadores aritméticos calcular el resultado de la operación aritmética específica y devuelve su resultado. Los argumentos no se modifican .
Original:
All arithmetic operators compute the result of specific arithmetic operation and returns its result. The arguments are not modified.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Conversiones

Si el operando pasa a un operador aritmético es integral o tipo de enumeración sin ámbito, a continuación, antes de cualquier otra acción (pero después de la conversión valori-a-valor-, si corresponde), el operando se somete promoción integral. Si un operando es de tipo matriz o función, arreglo a puntero y la función de puntero a las conversiones se aplican .
Original:
If the operand passed to an arithmetic operator is integral or unscoped enumeration type, then before any other action (but after lvalue-to-rvalue conversion, if applicable), the operand undergoes promoción integral. If an operand has array or function type, array-to-pointer and function-to-pointer conversions are applied.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para los operadores binarios (excepto turnos), si los operandos promovidos tienen diferentes tipos, juego adicional de conversiones implícitas se aplica, conocido como' conversiones aritméticas habituales con el objetivo de producir el tipo común' (también accesible a través el rasgo tipo std::common_type)
Original:
For the binary operators (except shifts), if the promoted operands have different types, additional set of implicit conversions is applied, known as usual arithmetic conversions with the goal to produce the common type (also accessible via the std::common_type type trait)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Si alguno de los operandos es de tipo enumeración ámbito, sin conversión que se realiza el otro operando y el tipo de retorno debe tener el mismo tipo
    Original:
    If either operand has scoped enumeration type, no conversion is performed: the other operand and the return type must have the same type
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, si alguno de los operandos es long double, el otro operando se convierte a long double
    Original:
    Otherwise, if either operand is long double, the other operand is converted to long double
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, si alguno de los operandos es double, el otro operando se convierte a double
    Original:
    Otherwise, if either operand is double, the other operand is converted to double
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, si alguno de los operandos es float, el otro operando se convierte a float
    Original:
    Otherwise, if either operand is float, the other operand is converted to float
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, el operando es de tipo entero (porque bool, char, char16_t, char32_t, wchar_t y enumeración sin ámbito se promovieron en este punto) y conversiones integrales se aplican para producir el tipo común, de la siguiente manera:
    Original:
    Otherwise, the operand has integer type (because bool, char, char16_t, char32_t, wchar_t, and unscoped enumeration were promoted at this point) and conversiones integrales are applied to produce the common type, as follows:
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si ambos operandos son firmados o ambos están sin firmar, operando con menor grado de conversión' se convierte en el operando con el rango entero de conversión mayor
    Original:
    If both operands are signed or both are unsigned, the operand with lesser conversion rank is converted to the operand with the greater integer conversion rank
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, si el rango operando sin signo de conversión es mayor o igual que el rango de conversión del operando con signo, el operando con signo se convierte al tipo del operando sin signo de .
    Original:
    Otherwise, if the unsigned operand's conversion rank is greater or equal to the conversion rank of the signed operand, the signed operand is converted to the unsigned operand's type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, si la firma operando de tipo puede representar todos los valores del operando sin signo, el operando sin signo se convierte al tipo del operando firmante
    Original:
    Otherwise, if the signed operand's type can represent all values of the unsigned operand, the unsigned operand is converted to the signer operand's type
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • De lo contrario, los dos operandos se convierten a la contraparte sin signo de tipo del operando firmada por .
    Original:
    Otherwise, both operands are converted to the unsigned counterpart of the signed operand's type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
El rango de conversión' por encima de los aumentos para bool, signed char, short, int, long, long long. El rango de cualquier tipo sin signo es igual al rango de la clase correspondiente firmado. El rango de char es igual al rango de signed char y unsigned char. Las filas de char16_t, char32_t y wchar_t son iguales a las filas de sus tipos subyacentes .
Original:
The conversion rank above increases in order bool, signed char, short, int, long, long long. The rank of any unsigned type is equal to the rank of the corresponding signed type. The rank of char is equal to the rank of signed char and unsigned char. The ranks of char16_t, char32_t, and wchar_t are equal to the ranks of their underlying types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Desbordamientos

Aritmética de enteros sin signo se realiza siempre modulo 2n
donde n es el número de bits en ese entero particular. Por ejemplo para unsigned int, sumando uno al UINT_MAX da 0, y restando una de 0 da UINT_MAX .
Original:
Unsigned integer arithmetic is always performed modulo 2n
where n is the number of bits in that particular integer. E.g. for unsigned int, adding one to UINT_MAX gives 0, and subtracting one from 0 gives UINT_MAX.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cuando entero con signo de desbordamientos operación aritmética (el resultado no cabe en el tipo de resultado), el comportamiento no está definido: se puede envolver alrededor de acuerdo con las reglas de la representación (normalmente complemento a 2), se puede atrapar en algunas plataformas o debido a compilador opciones (por ejemplo -ftrapv en GCC y Clang), o puede ser completamente optimized out by the compiler .
Original:
When signed integer arithmetic operation overflows (the result does not fit in the result type), the behavior is undefined: it may wrap around according to the rules of the representation (typically 2's complement), it may trap on some platforms or due to compiler options (e.g. -ftrapv in GCC and Clang), or may be completely optimized out by the compiler.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Los operadores unarios aritméticas

Para cada tipo promocionado A aritmética y para cada tipo T, las firmas de función siguientes participar en la resolución de sobrecarga:
Original:
For every promoted arithmetic type A and for every type T, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
A operator+(A)
T* operator+(T*)
A operator-(A)
La orden interna más unario devuelve el valor de su operando. La única situación donde no es un no-op es cuando el operando tiene tipo integral o de tipo de enumeración sin ámbito, que se cambia por promoción integral, por ejemplo, convierte a char int o, si el operando es objeto de valor-i-a-rvalue array a puntero, o función de conversión a puntero .
Original:
The builtin unary plus operator returns the value of its operand. The only situation where it is not a no-op is when the operand has integral type or unscoped enumeration type, which is changed by integral promotion, e.g, it converts char to int or if the operand is subject to lvalue-to-rvalue, array-to-pointer, or function-to-pointer conversion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
El operador unario menos builtin calcula la negativa de su operando. Para a sin signo, el valor de -a es 2b
-a
, donde b es el número de bits después de la promoción .
Original:
The builtin unary minus operator calculates the negative of its operand. For unsigned a, the value of -a is 2b
-a
, where b is the number of bits after promotion.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 0x6a;
    int n1 = 1;
    unsigned char n2 = 1;
    unsigned int n3 = 1;
    std::cout << "char: " << c << " int: " << +c << '\n'
              << "-1, where 1 is signed: " << -n1 << '\n'
              << "-1, where 1 is unsigned char: " << -n2 << '\n'
              << "-1, where 1 is unsigned int: " << -n3 << '\n';
    char a[3];
    std::cout << "size of array: " << sizeof a << '\n'
              << "size of pointer: " << sizeof +a << '\n';
}

Output:

char: j int: 106
-1, where 1 is signed: -1
-1, where 1 is unsigned char: -1
-1, where 1 is unsigned int: 4294967295
size of array: 3
size of pointer: 8

[editar] Operadores aditivos

Por cada par de tipos aritméticos promovidas L y R y para cada tipo de objeto T, las firmas de función siguientes participar en la resolución de sobrecarga:
Original:
For every pair of promoted arithmetic types L and R and for every object type T, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
LR operator+(L, R)
LR operator-(L, R)
T* operator+(T*, std::ptrdiff_t)
T* operator+(std::ptrdiff_t, T*)
T* operator-(T*, std::ptrdiff_t)
std::ptrdiff_t operator-(T*, T*)
donde LR es el resultado de las conversiones aritméticas habituales sobre L y R
Original:
where LR is the result of usual arithmetic conversions on L and R
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Con operandos de tipo aritmético o enumeración, el resultado de binario ventaja es la suma de los operandos (después de converesions aritméticas habituales), y el resultado de la binaria menos operador es el resultado de restar el segundo operando del primero (después de conversiones aritméticas habituales ) .
Original:
With operands of arithmetic or enumeration type, the result of binary plus is the sum of the operands (after usual arithmetic converesions), and the result of the binary minus operator is the result of subtracting the second operand from the first (after usual arithmetic conversions).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si alguno de los operandos es un puntero, aplican las siguientes reglas:
Original:
If any of the operands is a pointer, the following rules apply:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Un puntero al objeto a matriz es tratado como un puntero al primer elemento de una matriz con un tamaño de 1 .
    Original:
    A pointer to non-array object is treated as a pointer to the first element of an array with size 1.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si los puntos P puntero se convierte en el elemento ith de una matriz, entonces las expresiones P+n, n+P y P-n son punteros del mismo tipo que apuntan a la i+nth, i+nth y i-nth elemento de la misma matriz, respectivamente. El resultado de la adición de puntero también puede ser un puntero de un pasa-el-final (es decir, puntero P tal que los puntos P-1 expresión hasta el último elemento de la matriz). Cualquier otras situaciones (es decir, los intentos de generar un puntero que no está apuntando a un elemento de la misma matriz o una más allá del final) invocar un comportamiento no definido .
    Original:
    If the pointer P points to the ith element of an array, then the expressions P+n, n+P, and P-n are pointers of the same type that point to the i+nth, i+nth, and i-nth element of the same array, respectively. The result of pointer addition may also be a one-past-the-end pointer (that is, pointer P such that the expression P-1 points to the last element of the array). Any other situations (that is, attempts to generate a pointer that isn't pointing at an element of the same array or one past the end) invoke undefined behavior.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si los puntos P puntero se convierte en el elemento ith de una matriz, y los puntos Q puntero en el elemento jth de la misma matriz, la P-Q expresión tiene el valor i-j, si el valor se ajusta en std::ptrdiff_t. Ambos operandos debe apuntar a los elementos de la misma matriz (o uno más allá del final), de lo contrario el comportamiento es indefinido. Si el resultado no se ajusta a std::ptrdiff_t, el comportamiento no está definido .
    Original:
    If the pointer P points to the ith element of an array, and the pointer Q points at the jth element of the same array, the expression P-Q has the value i-j, if the value fits in std::ptrdiff_t. Both operands must point to the elements of the same array (or one past the end), otherwise the behavior is undefined. If the result does not fit in std::ptrdiff_t, the behavior is undefined.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si el valor 0 se añade o se resta de un puntero, el resultado es el puntero, sin cambios. Si dos punteros apuntan al mismo objeto o son un más allá del final de la misma matriz, o ambos son punteros nulos, entonces el resultado de la resta es igual a (std::ptrdiff_t)0 .
    Original:
    If the value 0 is added or subtracted from a pointer, the result is the pointer, unchanged. If two pointers point at the same object or are both one past the end of the same array, or both are null pointers, then the result of subtraction is equal to (std::ptrdiff_t)0.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Estos operadores aritméticos permiten puntero punteros para satisfacer el concepto RandomAccessIterator .
Original:
These pointer arithmetic operators allow pointers to satisfy the RandomAccessIterator concept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 2;
    unsigned int un = 2;
    int  n = -10;
    std::cout <<  " 2 + (-10), where 2 is a char    = " << c + n << '\n'
              <<  " 2 + (-10), where 2 is unsigned  = " << un + n << '\n'
              <<  " -10 - 2.12  = " << n - 2.12 << '\n';
 
    char a[4] = {'a', 'b', 'c', 'd'};
    char* p = &a[1];
    std::cout << "Pointer addition examples: " << *p << *(p + 2)
              << *(2 + p) << *(p - 1) << '\n';
    char* p2 = &a[4];
    std::cout << "Pointer difference: " << p2 - p << '\n';
}

Output:

2 + (-10), where 2 is a char    = -8
 2 + (-10), where 2 is unsigned  = 4294967288
 -10 - 2.12  = -12.12
Pointer addition examples: bdda
Pointer difference: 3

[editar] Los operadores multiplicativos

Por cada par de tipos aritméticos promovidas LA y RA y por cada par de tipos integrales promovidas LI y RI las siguientes firmas de función participar en la resolución de sobrecarga:
Original:
For every pair of promoted arithmetic types LA and RA and for every pair of promoted integral types LI and RI the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
LRA operator*(LA, RA)
LRA operator/(LA, RA)
LRI operator%(LI, RI)
donde LRx es el resultado de las conversiones aritméticas habituales sobre Lx y Rx
Original:
where LRx is the result of usual arithmetic conversions on Lx and Rx
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
* El operador binario realiza la multiplicación de sus operandos (después de las conversiones aritméticas habituales) .
Original:
The binary operator * performs multiplication of its operands (after usual arithmetic conversions).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
El operador binario / divide el primer operando por el segundo (después de las conversiones aritméticas habituales). Si el segundo operando es nulo, el comportamiento no está definido. En los operandos integrales, produce el cociente algebraico
Original:
The binary operator / divides the first operand by the second (after usual arithmetic conversions).If the second operand is zero, the behavior is undefined. For integral operands, it yields the algebraic quotient
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • redondeado en definido por la implantación (hasta C++11) dirección
    Original:
    rounded in implementation-defined direction (hasta C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • con cualquier parte fraccionaria descartado (truncado a cero) (desde C++11)
    Original:
    with any fractional part discarded (truncated towards zero) (desde C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
El operador binario% produce el resto de la división del primer operando por el segundo (después de conversiones aritméticas habituales). Si el cociente es a/b representible en el tipo de resultado, (a/b)*b + a%b == a. Si el segundo operando es cero, el comportamiento es indefinido .
Original:
The binary operator % yields the remainder of the division of the first operand by the second (after usual arithmetic conversions). If the quotient a/b is representible in the result type, (a/b)*b + a%b == a. If the second operand is zero, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • si uno o ambos operandos son negativos, la señal de que el resto es definido por la implementación, ya que depende de la dirección de redondeo de (hasta C++11) división entera
    Original:
    if one or both operands are negative, the sign of the remainder is implementation-defined, as it depends on the rounding direction of integer division (hasta C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    char c = 2;
    unsigned int un = 2;
    int  n = -10;
    std::cout <<  "2 * (-10), where 2 is a char    = " << c * n << '\n'
              <<  "2 * (-10), where 2 is unsigned  = " << un * n << '\n'
              <<  "-10 / 2.12  = " << n / 2.12 << '\n'
              <<  "-10 / 21  = " << n / 21 << '\n'
              <<  "-10 % 21  = " << n % 21 << '\n';
}

Output:

2 * (-10), where 2 is a char    = -20
2 * (-10), where 2 is unsigned  = 4294967276
-10 / 2.12  = -4.71698
-10 / 21  = 0
-10 % 21  = -10

[editar] Bit a bit Los operadores lógicos

Por cada par de tipos integrales promovidas L y R las siguientes firmas de función participar en la resolución de sobrecarga:
Original:
For every pair of promoted integral types L and R the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
R operator~(R)
LR operator&(L, R)
LR operator^(L, R)
LR operator|(L, R)
donde LR es el resultado de las conversiones aritméticas habituales sobre L y R
Original:
where LR is the result of usual arithmetic conversions on L and R
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
El resultado del operador ~ es el NO bit a bit (complemento a uno) valor del argumento (después de la promoción). El resultado del operador & es el operador de bits y el valor de los operandos (después de las conversiones aritméticas habituales). El resultado del operador
Original:
es el valor de OR bit a bit de los operandos (después de las conversiones aritméticas habituales). El resultado del operador ^ es el valor XOR bit a bit de los operandos (después de las conversiones aritméticas habituales)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
int main()
{
    std::cout << std::hex << std::showbase;
    uint16_t mask = 0x00f0;
    uint32_t a = 0x12345678;
    std::cout << "Value: " << a << " mask: " << mask << '\n'
              << "Setting bits: " << (a

Output:

Value: 0x12345678 mask: 0xf0
Setting bits: 0x123456f8
Clearing bits: 0x12345608
Selecting bits: 0x70

[editar] Bit a bit Operadores de desplazamiento

Por cada par de tipos integrales promovidas L y R, las firmas de función siguientes participar en la resolución de sobrecarga:
Original:
For every pair of promoted integral types L and R, the following function signatures participate in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
L operator<<(L, R)
L operator>>(L, R)
Los operandos de los operadores integrados desplazamiento en modo bit tienen tipos ya sea integral o el tipo de enumeración sin ámbito. Promociones integrales se realizan en ambos operandos antes de la evaluación. El tipo devuelto es el tipo del operando de la izquierda después de las promociones integal .
Original:
The operands of the built-in bitwise shift operators have either integral types or unscoped enumeration type. Integral promotions are performed on both operands before evaluation. The return type is the type of the left operand after integal promotions.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para a sin signo, el valor de a << b es el valor de a * 2b
, reducido valor de módulo máximo del tipo de retorno más 1 (es decir, desplazamiento bit a bit a la izquierda se lleva a cabo y los bits que se desplazan fuera del tipo de destino se descartan). Para a firmado, el valor de a << b es a * 2b
si es representable por el tipo de retorno, de lo contrario el comportamiento es indefinido .
Original:
For unsigned a, the value of a << b is the value of a * 2b
, reduced modulo maximum value of the return type plus 1 (that is, bitwise left shift is performed and the bits that get shifted out of the destination type are discarded). For signed a, the value of a << b is a * 2b
if it is representable by the return type, otherwise the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Para a sin signo y para a firmado con valores no negativos, el valor de a >> b es la parte entera de a/2b
. Para a negativo, el valor de a >> b es definido por la implantación (en la mayoría de las implementaciones, este realiza desplazamiento aritmético a la derecha, de modo que el resultado sigue siendo negativo)
Original:
For unsigned a and for signed a with nonnegative values, the value of a >> b is the integer part of a/2b
. For negative a, the value of a >> b is implementation-defined (in most implementations, this performs arithmetic right shift, so that the result remains negative)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
En cualquier caso, si el valor del operando derecho es negativo o es mayor o igual que el número de bits en el operando promovido izquierda, el comportamiento es indefinido .
Original:
In any case, if the value of the right operand is negative or is greater or equal to the number of bits in the promoted left operand, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream>
enum {ONE=1, TWO=2};
int main()
{
    std::cout << std::hex << std::showbase;
    char c = 0x10;
    unsigned long long ull = 0x123;
    std::cout << "0x123 << 1 = " << (ull << 1) << '\n'
              << "0x123 << 63 = " << (ull << 63) << '\n' // overflow in unsigned
              << "0x10 << 10 = " << (c << 10) << '\n';   // char is promoted to int
    long long ll = -1000;
    std::cout << std::dec << "-1000 >> 1 = " << (ll >> ONE) << '\n';
}

Output:

0x123 << 1 = 0x246
0x123 << 63 = 0x8000000000000000
0x10 << 10 = 0x4000
-1000 >> 1 = -500

[editar] Biblioteca estándar

Los operadores aritméticos están sobrecargados para muchos tipos de la biblioteca estándar .
Original:
Arithmetic operators are overloaded for many standard library types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Los operadores unarios aritméticas

implementa + unario y - unario
Original:
implements unary + and unary -
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::chrono::duration función) [edit]
aplica a los operadores unarios números complejos
Original:
applies unary operators to complex numbers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
se aplica un operador aritmético unario a cada elemento de la valarray
Original:
applies a unary arithmetic operator to each element of the valarray
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::valarray función) [edit]

[editar] Operadores aditivos

modifica el punto de tiempo por la duración dada
Original:
modifies the time point by the given duration
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
concatena dos cadenas o una cadena de caracteres y una
Original:
concatenates two strings or a string and a char
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
avanza el iterador
Original:
advances the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::reverse_iterator función)
Disminuye el iterador
Original:
decrements the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::reverse_iterator función)
avanza el iterador
Original:
advances the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::move_iterator función)
Disminuye el iterador
Original:
decrements the iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::move_iterator función)
realiza la aritmética de números complejos en dos valores complejos o complejos a escalar
Original:
performs complex number arithmetics on two complex values or a complex and a scalar
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
operadores binarios se aplica a cada elemento de dos valarrays, o un valarray y un valor
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]

[editar] Los operadores multiplicativos

implementa las operaciones aritméticas con duraciones como argumentos
Original:
implements arithmetic operations with durations as arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
realiza la aritmética de números complejos en dos valores complejos o complejos a escalar
Original:
performs complex number arithmetics on two complex values or a complex and a scalar
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
operadores binarios se aplica a cada elemento de dos valarrays, o un valarray y un valor
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]

[editar] Bit a bit Los operadores lógicos

realiza binario AND, OR, XOR y NOT
Original:
performs binary AND, OR, XOR and NOT
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::bitset función) [edit]
realiza operaciones lógicas binarias en bitsets
Original:
performs binary logic operations on bitsets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función) [edit]
se aplica un operador aritmético unario a cada elemento de la valarray
Original:
applies a unary arithmetic operator to each element of the valarray
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::valarray función)
operadores binarios se aplica a cada elemento de dos valarrays, o un valarray y un valor
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla)

[editar] Bit a bit Operadores de desplazamiento

operadores binarios se aplica a cada elemento de dos valarrays, o un valarray y un valor
Original:
applies binary operators to each element of two valarrays, or a valarray and a value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla)
realiza izquierda binario desplazamiento y desplazamiento a la derecha
Original:
performs binary shift left and shift right
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::bitset función)

[editar] Flujo de inserción / extracción de los operadores

A lo largo de la biblioteca estándar, operadores de bits de desplazamiento están comúnmente sobrecargado con E / S de corriente (std::ios_base& o una de las clases derivadas de él) ya que tanto el operando de la izquierda y el tipo de retorno. Estos operadores se conocen como corriente de inserción y de extracción''' operadores de corriente:
Original:
Throughout the standard library, bitwise shift operators are commonly overloaded with I/O stream (std::ios_base& or one of the classes derived from it) as both the left operand and return type. Such operators are known as stream insertion and stream extraction operators:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
extractos de formato de datos
Original:
extracts formatted data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::basic_istream función) [edit]
extrae caracteres y arrays de caracteres
Original:
extracts characters and character arrays
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
insertos de formato de datos
Original:
inserts formatted data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(miembro público of std::basic_ostream función) [edit]
inserciones de datos de caracteres
Original:
inserts character data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función) [edit]
serializa y deserializa un número complejo
Original:
serializes and deserializes a complex number
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
realiza flujo de entrada y salida de bitsets
Original:
performs stream input and output of bitsets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función) [edit]
realiza secuencia de E / S en cadenas
Original:
performs stream I/O on strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
realiza flujo de entrada y de salida en el motor de número pseudo-aleatorio
Original:
performs stream input and output on pseudo-random number engine
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función) [edit]
realiza flujo de entrada y salida en la distribución de números pseudo-aleatorios
Original:
performs stream input and output on pseudo-random number distribution
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función) [edit]

[editar] Ver también

La precedencia de operadores

Common operators
asignación incrementNJdecrement aritmética lógico comparación memberNJaccess otro

a = b
a = rvalue
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
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
? :

Special operators
static_cast convierte un tipo a otro tipo
compatible
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 convierte clase base virtual a class
derivada
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 convierte un tipo a otro compatible con diferentes cv qualifiers
Original:
const_cast converts type to compatible type with different cv qualifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reinterpret_cast convierte el tipo de type
incompatible
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 asigna 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 desasigna 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 consulta el tamaño de 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... consulta el tamaño de un parámetro de paquete (desde C++11)
Original:
sizeof... queries the size of a parámetro de paquete (desde C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typeid consulta la información de 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 comprueba si una expresión puede lanzar una excepción (desde C++11)
Original:
noexcept checks if an expression can throw an exception (desde C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alignof consultas requisitos de alineación de un (desde C++11) tipo
Original:
alignof queries alignment requirements of a type (desde C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.