Namespace
Varianti

Arithmetic operators

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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)
Specifiers
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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 alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della 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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
esplicito (C++11)
statico
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
Restituisce il risultato della operazione aritmetica specifica.
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);
'Nota'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Tutti incorporato valori restituiti operatori, e più definiti dall'utente sovraccarichi anche restituire valori in modo che gli operatori definiti dall'utente possono essere utilizzati nello stesso modo come il built-in. Tuttavia, in una definita dall'utente overload dell'operatore, qualsiasi tipo può essere utilizzato come tipo di ritorno (compresa void). In particolare, l'inserimento flusso e sovraccarichi flusso di estrazione di operator<< e operator>> ritorno 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 può essere qualsiasi tipo comprendente 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.

Indice

[modifica] Spiegazione

Tutti gli operatori aritmetici calcolare il risultato di un'operazione aritmetica specifico e restituisce il risultato. Gli argomenti non vengono modificati.
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.

[modifica] Conversioni

Se l'operando passato a un operatore aritmetico è integrale o tipo di enumerazione senza ambito, quindi prima di ogni altra azione (ma dopo lvalue a rvalue conversione, se applicabile), l'operando subisce promozione integrale. Se un operando di tipo array o funzione, l'array a puntatore e la funzione a puntatore conversioni vengono applicate.
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 promozione integrale. 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.
Per gli operatori binari (tranne turni), se gli operandi hanno promosso diversi tipi, set supplementare di conversioni implicite è applicato, conosciuto come conversioni aritmetiche usuali con l'obiettivo di produrre il tipo di comune (accessibile anche tramite il tipo di tratto 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.
  • Se uno degli operandi è di tipo ambito di enumerazione, la conversione non viene eseguita: l'altro operando e il tipo di ritorno deve avere lo stesso 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.
  • Altrimenti, se uno degli operandi è long double, l'altro operando viene convertito in 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.
  • Altrimenti, se uno degli operandi è double, l'altro operando viene convertito in 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.
  • Altrimenti, se uno degli operandi è float, l'altro operando viene convertito in 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.
  • In caso contrario, l'operando è di tipo integer (perché bool, char, char16_t, char32_t, wchar_t, e l'enumerazione senza ambito sono stati promossi a questo punto) e conversioni integrali sono applicati per produrre il tipo comune, come segue:
    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 conversioni integrali 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.
  • Se entrambi gli operandi sono firmati o entrambi non sono firmati, l'operando con minore rango conversione viene convertito l'operando con il grado numero intero maggiore di conversione
    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.
  • In caso contrario, se rango di conversione l'operando unsigned è maggiore o uguale al rango di conversione dell'operando firmato, firmato l'operando viene convertito il tipo di operando unsigned di.
    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.
  • Altrimenti, se il sottoscritto operando del tipo può rappresentare tutti i valori della operando unsigned, l'operando unsigned viene convertito al tipo dell'operando firmatario
    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.
  • In caso contrario, entrambi gli operandi vengono convertiti alla controparte non firmato del tipo dell'operando firmato il.
    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.
Il rango di conversione' sopra gli aumenti per bool, signed char, short, int, long, long long. Il rango di qualsiasi tipo senza segno è uguale al rango di tipo corrispondente firmato. Il rango di char è uguale al rango di signed char e unsigned char. I ranghi dei char16_t, char32_t e wchar_t sono uguali al rango di loro tipi sottostanti.
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.

[modifica] Overflow

Unsigned aritmetica intera è sempre eseguita modulo 2n
dove n è il numero di bit in tale particolare numero intero. Ad es per unsigned int, aggiungendo uno al UINT_MAX0, e sottraendo uno da 0UINT_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.
Quando ha firmato integer overflow operazione aritmetica (il risultato non rientra nel tipo di risultato), il comportamento è indefinito: si può avvolgere intorno secondo le regole della rappresentazione (tipicamente complemento a 2), può intrappolare su alcune piattaforme o tenuto conto del compilatore opzioni (ad esempio -ftrapv in GCC e Clang), o possono essere 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.

[modifica] Operatori aritmetici unari

Per ogni A aritmetica promosso tipo e per ogni tipo di T, le firme delle funzioni seguenti partecipare risoluzione di sovraccarico:
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)
Il builtin più unario operatore restituisce il valore del suo operando. L'unica situazione in cui non è un no-op è quando l'operando ha tipo integrale o tipo di enumerazione senza ambito, che viene modificato promozione integrale, ad esempio, converte char a int o se l'operando è soggetto a lvalue-to-rvalue, array a puntatore, o una funzione a puntatore di conversione.
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.
L'operatore unario meno incorporato calcola il negativo del suo operando. Per a unsigned, il valore di -a è 2b
-a
, dove b è il numero di bit dopo promozione.
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

[modifica] Additivi operatori

Per ogni coppia di tipi aritmetici promosso L e R e per ogni tipo di oggetto T, le firme delle funzioni seguenti partecipare risoluzione di sovraccarico:
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*)
dove LR è il risultato di conversioni aritmetiche usuali su L e 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 operandi di tipo aritmetico o enumerazione, il risultato binario plus è la somma degli operandi (dopo converesions aritmetiche usuali), e il risultato del binario meno operatore è il risultato della sottrazione del secondo operando dal primo (dopo conversioni aritmetiche abituali ).
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.
Se uno degli operandi è un puntatore, valgono le seguenti regole:
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 puntatore di non-array oggetto è trattato come un puntatore al primo elemento di un array di dimensione 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.
  • Se i punti di puntatore P all'elemento ith di un array, quindi le espressioni P+n, n+P e P-n sono puntatori dello stesso tipo che puntano al i+nth, i+nth, ed elemento i-nth dello stesso array, rispettivamente. Il risultato di aggiunta puntatore può anche essere un-passato-la-end puntatore (cioè puntatore P tale che i punti di espressione P-1 all'ultimo elemento della matrice). Eventuali altre situazioni (cioè, tenta di generare un puntatore che non punta ad un elemento della matrice stessa o uno oltre la fine) invocare comportamento indefinito.
    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.
  • Se i punti di puntatore P all'elemento ith di un array, ed i punti Q puntatore al jth elemento della matrice stessa, l'espressione ha il P-Q i-j valore, se il valore rientra nel std::ptrdiff_t. Entrambi gli operandi devono indicare gli elementi della matrice stessa (o uno oltre la fine), altrimenti il ​​comportamento è indefinito. Se il risultato non rientra nel std::ptrdiff_t, il comportamento non è definito.
    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.
  • Se il valore 0 viene aggiunto o sottratto un puntatore, il risultato è il puntatore, invariato. Se due puntatori a punto lo stesso oggetto o sono due un popolo solo dopo la fine della matrice stessa, o entrambi sono puntatori nulli, allora il risultato della sottrazione è uguale 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.
Questi operatori aritmetici puntatore puntatori permettono di soddisfare il concetto 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

[modifica] Operatori moltiplicativi

Per ogni coppia di tipi aritmetici promosso LA e RA e per ogni coppia di tipi integrali promosse LI e RI i seguenti firme delle funzioni partecipare risoluzione di sovraccarico:
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)
dove LRx è il risultato di conversioni aritmetiche usuali su Lx e 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.
L'operatore binario * esegue la moltiplicazione dei suoi operandi (dopo conversioni aritmetiche usuali).
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.
L'operatore binario / divide il primo operando per il secondo (dopo conversioni aritmetiche abituali). Se il secondo operando è zero, il comportamento è indefinito. Per gli operandi integrali, cede il quoziente algebrica
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.
  • arrotondato in attuazione definito (fino al c++11) direzione
    Original:
    rounded in implementation-defined direction (fino al 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 qualsiasi parte frazionaria scartata (troncato verso zero) (dal C++11)
    Original:
    with any fractional part discarded (truncated towards zero) (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.
L'operatore binario% produce il resto della divisione del primo operando per il secondo (dopo conversioni aritmetiche usuali). Se il quoziente è a/b representible nel tipo di risultato, (a/b)*b + a%b == a. Se il secondo operando è zero, il comportamento non è definito.
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.
  • se uno o entrambi gli operandi sono negativi, il segno del resto è definito dall'implementazione, in quanto dipende dalla direzione di arrotondamento (fino al c++11) divisione intera
    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 (fino al 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

[modifica] Bit a bit logici operatori

Per ogni coppia di tipi integrali promosse L e R i seguenti firme delle funzioni partecipare risoluzione di sovraccarico:
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)
dove LR è il risultato di conversioni aritmetiche usuali su L e 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.
Il risultato è l'operatore ~ ​​NOT bit a bit (complemento a uno), valore dell'argomento (dopo la promozione). Il risultato dell'operatore & AND bit a bit è il valore degli operandi (dopo conversioni aritmetiche abituali). Il risultato dell'operatore
Original:
è il valore di OR bit a bit degli operandi (dopo conversioni aritmetiche abituali). Il risultato di operatore ^ è il valore XOR bit a bit degli operandi (dopo conversioni aritmetiche abituali)
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

[modifica] Spostamento bit a bit operatori

Per ogni coppia di tipi integrali promosse L e R, le firme delle funzioni seguenti partecipare risoluzione di sovraccarico:
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)
Gli operandi di operatori built-in spostamento bit a bit hanno tipi o integrali o il tipo di enumerazione senza ambito. Promozioni integrali vengono eseguite su entrambi gli operandi prima valutazione. Il tipo restituito è il tipo di operando di sinistra, dopo le promozioni 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.
Per a unsigned, il valore della a << b è il valore di a * 2b
, ridotto valore modulo massimo del tipo di ritorno più 1 (che è, scorrimento a sinistra viene eseguita ei bit che vengono fatti scorrere del tipo di destinazione vengono scartati). Per a firmato, il valore di a << b è a * 2b
se è rappresentabile dal tipo restituito, altrimenti il ​​comportamento è indefinito.
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.
Per a senza segno e per a firmato con valori non negativi, il valore della a >> b è la parte intera di a/2b
. Per a negativo, il valore di a >> b è definito dall'implementazione (nella maggior parte delle implementazioni, questa esegue spostamento aritmetico a destra, in modo che il risultato resta 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.
In ogni caso, se il valore dell'operando di destra è negativo o è maggiore o uguale al numero di bit nella operando promosso sinistra, il comportamento è indefinito.
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

[modifica] Libreria standard

Gli operatori aritmetici sono sovraccarichi per molti tipi di libreria standard.
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.

[modifica] Operatori aritmetici unari

implementa + unario e unario -. copie
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.

(metodo pubblico) [modifica]
si applica operatori unari ai numeri complessi
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.

(funzione di modello) [modifica]
applica un operatore unario aritmetica per ogni elemento del 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.

(metodo pubblico) [modifica]

[modifica] Additivi operatori

modifica il punto di tempo dalla data durata
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.

(funzione di modello) [modifica]
concatena due stringhe od una stringa ed un carattere
(funzione di modello) [modifica]
avanza l'iteratore
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.

(metodo pubblico)
decrementa l'iteratore
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.

(metodo pubblico)
avanza l'iteratore
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.

(metodo pubblico)
decrementa l'iteratore
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.

(metodo pubblico)
esegue aritmetica di numeri complessi su due valori complessi o un complesso e scalari
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.

(funzione di modello) [modifica]
vale operatori binari a ciascun elemento di due valarrays, o un valarray e un valore
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.

(funzione di modello) [modifica]

[modifica] Operatori moltiplicativi

implementa operazioni aritmetiche con durate come argomenti
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.

(funzione di modello) [modifica]
esegue aritmetica di numeri complessi su due valori complessi o un complesso e scalari
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.

(funzione di modello) [modifica]
vale operatori binari a ciascun elemento di due valarrays, o un valarray e un valore
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.

(funzione di modello) [modifica]

[modifica] Bit a bit logici operatori

esegue binaria AND, OR, XOR e 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.

(metodo pubblico) [modifica]
esegue le operazioni logiche su binari bitset
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.

(funzione) [modifica]
applica un operatore unario aritmetica per ogni elemento del 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.

(metodo pubblico)
vale operatori binari a ciascun elemento di due valarrays, o un valarray e un valore
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.

(funzione di modello)

[modifica] Spostamento bit a bit operatori

vale operatori binari a ciascun elemento di due valarrays, o un valarray e un valore
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.

(funzione di modello)
esegue spostamento a sinistra binario e spostamento a destra
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.

(metodo pubblico)

[modifica] Flusso di inserimento / estrazione operatori

Per tutta la libreria standard, operatori di spostamento bit a bit sono comunemente sovraccarico di I / O stream (std::ios_base& o una delle classi da essa derivate) sia come operando di sinistra e il tipo restituito. Tali operatori sono conosciuti come flusso di inserimento' e flusso di estrazione operatori:
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.
estratti i dati formattati
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.

(metodo pubblico) [modifica]
estrae i caratteri e array di caratteri
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.

(funzione di modello) [modifica]
inserisce i dati formattati
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.

(metodo pubblico) [modifica]
inserisce i dati carattere
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.

(funzione) [modifica]
serializza e deserializza un numero complesso
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.

(funzione di modello) [modifica]
esegue flusso di input e output di bitset
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.

(funzione) [modifica]
applica flussi di I/O alle stringhe
(funzione di modello) [modifica]
esegue flusso di ingresso e di uscita sul pseudo-casuale numero di motore
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.

(funzione) [modifica]
esegue flusso di ingresso e di uscita sul pseudo-casuale distribuzione numerica
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.

(funzione) [modifica]

[modifica] Vedi anche

Precedenza degli operatori

Common operators
assegnazione incrementNJdecrement aritmetica logico confronto memberNJaccess altra

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 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:
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 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:
sizeof... queries the size of a parametro confezione (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.
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:
noexcept checks if an expression can throw an exception (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.
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.