Espaces de noms
Variantes
Actions

Arithmetic operators

De cppreference.com
< cpp‎ | language

 
 
Langage C++
Sujets généraux
Contrôle de flux
Instructions conditionnelles
Instructions d'itération
Instructions de saut
Fonctions
déclaration de fonction
expression lambda
fonction générique
spécificateur inline
spécification d'exception (obsolète)
spécificateur noexcept (C++11)
Exceptions
Espaces de noms
Types
spécificateur decltype (C++11)
Qualificatifs
qualificatifs const et volatile
qualificatifs de stockage
qualificatif constexpr (C++11)
qualificatif auto (C++11)
qualificatif alignas (C++11)
Initialisation
Littéraux
Expressions
opérateurs alternatifs
Utilitaires
Types
déclaration typedef
déclaration d'alias de type (C++11)
attributs (C++11)
Jette
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversions implicites
conversion const_cast
conversion static_cast
conversion dynamic_cast
conversion reinterpret_cast
conversions style C et style fonction
Allocation de mémoire
Classes
Qualificatifs spécifiques aux membres de classe
Fonctions membres spéciales
Modèles
classes génériques
fonctions génériques
spécialisation de modèles
paquets de paramètres (C++11)
Divers
Assembleur
 
Retourne le résultat de l'opération arithmétique spécifique .
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 +aYes T T::operator+()const;T operator+(const T &a);
unary minus -aYes T T::operator-()const;T operator-(const T &a);
addition a + bYes T T::operator+(const T2 &b)const;T operator+(const T &a, const T2 &b);
subtraction a - bYes T T::operator-(const T2 &b)const;T operator-(const T &a, const T2 &b);
multiplication a * bYes T T::operator*(const T2 &b)const;T operator*(const T &a, const T2 &b);
division a / bYes T T::operator/(const T2 &b)const;T operator/(const T &a, const T2 &b);
modulo a % bYes T T::operator%(const T2 &b)const;T operator%(const T &a, const T2 &b);
bitwise NOT ~aYes T T::operator~()const;T operator~(const T &a);
bitwise AND a & bYes T T::operator&(const T2 &b)const;T operator&(const T &a, const T2 &b);
bitwise OR a | bYes T T::operator|(const T2 &b)const;T operator|(const T &a, const T2 &b);
bitwise XOR a ^ bYes T T::operator^(const T2 &b)const;T operator^(const T &a, const T2 &b);
bitwise left shift a << bYes T T::operator<<(const T2 &b)const;T operator<<(const T &a, const T2 &b);
bitwise right shift a >> bYes T T::operator>>(const T2 &b)const;T operator>>(const T &a, const T2 &b);
'Note'
Original:
Notes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • Tout intégré opérateurs valeurs de retour, et plus définies par l'utilisateur surcharges également renvoyer des valeurs de sorte que les opérateurs définis par l'utilisateur peuvent être utilisées de la même manière que le haut-ins. Cependant, définie par l'utilisateur surcharge d'opérateur, n'importe quel type peut être utilisé comme type de retour (y compris void). En d'insertion flux particulier, et les surcharges d'extraction de flux de operator<< et operator>> retour 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 peuvent être de tout type, y compris 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.

Sommaire

[modifier]Explication

Tous les opérateurs arithmétiques calculent le résultat de l'opération arithmétique spécifique et renvoie le résultat. Les arguments ne sont pas modifiés .
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.

[modifier]Conversions

Si l'opérande transmis à un opérateur arithmétique est entier ou type d'énumération sans portée, alors avant toute autre action (mais après lvalue rvalue à la conversion, le cas échéant), l'opérande subit promotion intégrale. Si un opérande est de type tableau ou fonction, un tableau à pointeur et la fonction à pointeur conversions sont appliquées .
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 promotion intégrale. 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.
Pour les opérateurs binaires (à l'exception des changements), si les opérandes ont favorisé types différents, ensemble supplémentaire de conversion implicite est appliquée, appelée' conversions arithmétiques usuelles dans le but de produire du type' commun (également accessible par l'intermédiaire d' le trait de type 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 l'un des opérandes est de type énumération portée, aucune conversion n'est effectuée: l'autre opérande et le type de retour doit avoir le même type
    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.
  • Dans le cas contraire, si l'un des opérandes est longdouble, l'autre opérande est converti en longdouble
    Original:
    Otherwise, if either operand is longdouble, the other operand is converted to longdouble
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Dans le cas contraire, si l'un des opérandes est double, l'autre opérande est converti en 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.
  • Dans le cas contraire, si l'un des opérandes est float, l'autre opérande est converti en 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.
  • Dans le cas contraire, l'opérande est de type entier (parce que bool, char, char16_t, char32_t, wchar_t, sans portée et le dénombrement ont été promus à ce stade) et conversions intégrales sont appliquées pour produire le type commun, comme suit:
    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 conversions intégrales 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 les deux opérandes sont signés ou les deux ne sont pas signés, l'opérande avec moins' rang de conversion est converti à l'opérande avec le grade de conversion supérieur entier
    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.
  • Dans le cas contraire, si le rang de conversion opérande non signé est supérieur ou égal au rang de conversion de l'opérande signé, l'opérande signé est converti en type de l'opérande non signé 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.
  • Sinon, si le type signé opérande peut représenter toutes les valeurs de l'opérande non signé, l'opérande non signé est converti en type de l'opérande signataire
    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.
  • Sinon, les deux opérandes sont convertis en contrepartie de type unsigned l'opérande signé le .
    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.
Le rang de conversion' ci-dessus augmente afin bool, signedchar, short, int, long, longlong. Le rang d'un type non signé est égal au rang du type correspondant signé. Le rang de char est égal au rang de signedchar et unsignedchar. Les rangs des char16_t, char32_t et wchar_t sont égaux dans les rangs de leurs types sous-jacents .
Original:
The conversion rank above increases in order bool, signedchar, short, int, long, longlong. 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 signedchar and unsignedchar. 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.

[modifier]Débordements

Arithmétique de nombres entiers non signés est toujours effectué modulo 2n
où n est le nombre de bits dans cet entier particulière. Par exemple pour unsignedint, ajoutant un UINT_MAX donne 0, et en soustrayant un de 0 donne 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 unsignedint, 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.
Une fois signée entier déborde d'opérations arithmétiques (le résultat ne rentre pas dans le type de résultat), le comportement est indéfini: il peut s'enrouler autour selon les règles de la représentation (généralement en complément à 2), il peut piéger sur certaines plates-formes ou en raison de compilateur options (par ex -ftrapv de GCC et Clang), ou peut être complètement 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.

[modifier]Opérateurs arithmétiques unaires

Pour chaque type arithmétique A promu et pour chaque type de T, les signatures de fonction suivants participent à la résolution de surcharge:
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)
Le unaire, plus builtin opérateur retourne la valeur de son opérande. La seule situation où il n'est pas un no-op, c'est quand l'opérande est de type intégral ou de type énumération sans portée, qui est modifiée par la promotion intégrale, par exemple, il se convertit à charint ou si l'opérande est soumise à lvalue-à-rvalue, array-à-pointeur, ou de la fonction à pointeur conversion .
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.
Le unaire moins builtin opérateur calcule le négatif de son opérande. Pour a non signé, la valeur de -a est 2b
-a
, où b est le nombre de bits après la promotion .
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;unsignedchar n2 =1;unsignedint 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';}

Résultat :

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

[modifier]Opérateurs d'ajout

Pour chaque paire de types arithmétiques promus L et R et pour chaque type d'objet T, les signatures de fonction suivants participent à la résolution de surcharge:
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*)
LR est le résultat de conversions arithmétiques habituelles sur L et 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.
Avec des opérandes de type arithmétique ou dénombrement, le résultat binaire en plus de la somme des opérandes (après converesions arithmétiques usuelles), et le résultat de l'opérateur binaire est moins le résultat de la soustraction du second opérande à partir de la première (après conversion arithmétiques usuelles ) .
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 l'un des opérandes est un pointeur, les règles suivantes s'appliquent:
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 pointeur non-ensemble objet est traité comme un pointeur vers le premier élément d'un tableau de taille 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 les points P pointeur vers l'élément ith d'un tableau, alors les expressions P+n, n+P et P-n sont des pointeurs du même type qui pointent vers le i+nth, i+nth, et l'élément i-nth du même réseau, respectivement. Le résultat de l'addition pointeur peut aussi être un pointeur d'un past-the-end (c'est-à-pointeur P tels que les points P-1 expression sur le dernier élément du tableau). Toutes les autres situations (c'est-à-tente de générer un pointeur qui ne pointe pas moins un élément du même réseau ou d'un passé à la fin) invoquer un comportement indéfini .
    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 les points P pointeur vers l'élément ith d'un tableau, et les points Q pointeur à l'élément jth de la même gamme, le P-Q expression a la valeur i-j, si la valeur s'inscrit dans std::ptrdiff_t. Les deux opérandes doivent pointer vers les éléments du tableau même (ou l'un après l'extrémité), sinon le comportement est indéfini. Si le résultat ne correspond pas à std::ptrdiff_t, le comportement est indéfini .
    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 le 0 valeur est ajoutée ou soustraite d'un pointeur, le résultat est le pointeur, inchangé. Si deux pointeurs ponctuelles au même objet ou sont à la fois un passé à la fin du même réseau, ou les deux sont des pointeurs NULL, alors le résultat de la soustraction est égal à (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.
Ces opérateurs arithmétiques de pointeur pointeurs permettent de satisfaire le concept 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;unsignedint 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';}

Résultat :

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

[modifier]Opérateurs de multiplication

Pour chaque paire de types arithmétiques promus LA et RA et pour chaque paire de types intégraux LI promus et RI la suite de signatures de fonction participer à la résolution de surcharge:
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)
LRx est le résultat de conversions arithmétiques habituelles sur Lx et 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'opérateur binaire * effectue la multiplication de ses opérandes (après conversions arithmétiques habituelles) .
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'opérateur binaire / divise le premier opérande par le second (après conversions arithmétiques habituelles). Si le second opérande est égal à zéro, le comportement est indéfini. Pour les opérandes entiers, il donne le quotient algébrique
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.
  • arrondis à la mise en oeuvre définie par (avant C++11) direction
    Original:
    rounded in implementation-defined direction (avant C++11)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • la partie décimale éliminée (tronquée vers zéro) (depuis C++11)
    Original:
    with any fractional part discarded (truncated towards zero) (depuis 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'opérateur binaire% donne le reste de la division du premier opérande par le second (après conversions arithmétiques habituelles). Si le quotient est a/b representible dans le type de résultat, (a/b)*b + a%b == a. Si le second opérande est égal à zéro, le comportement est indéfini .
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 une ou les deux opérandes sont négatifs, le signe du reste est définie par la mise en oeuvre, car elle dépend de la direction de l'arrondi (avant C++11) division entière
    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 (avant 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;unsignedint 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';}

Résultat :

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

[modifier]Opérateurs logiques bit à bit

Pour chaque paire de types intégraux L promus et R la suite de signatures de fonction participer à la résolution de surcharge:
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)
LR est le résultat de conversions arithmétiques habituelles sur L et 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.
Le résultat de l'opérateur ~ est l'opérateur bitwise NOT (complément) la valeur de l'argument (après la promotion). Le résultat de l'opérateur & est l'opérateur de bits AND valeur des opérandes (après conversions arithmétiques habituelles). Le résultat de l'opérateur
Original:
est un OU binaire valeur des opérandes (après conversions arithmétiques habituelles). Le résultat de l'opérateur ^ est la valeur XOR bit à bit de l'opérande (après conversion arithmétiques usuelles)
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

Résultat :

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

[modifier]Opérateurs de décalage au niveau du bit

Pour chaque paire de types intégraux L promus et R, les signatures de fonction suivants participent à la résolution de surcharge:
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)
Les opérandes de l'haut-opérateurs de décalage au niveau du bit des types soit intégré ou de type énumération sans portée. Promotions intégrales sont effectuées sur les deux opérandes avant l'évaluation. Le type de retour est le type de l'opérande gauche après les promotions 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.
Pour a non signé, la valeur de a << b est la valeur de a * 2b
, réduit modulo la valeur maximale du type de retour plus 1 (c'est-à-décalage gauche est effectuée et les bits qui se décalés hors du type de destination sont éliminés). Pour a signé, la valeur de a << b est a * 2b
s'il est représentable par le type de retour, sans quoi le comportement n'est pas défini .
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.
Pour a non signé et pour a signé avec des valeurs non négatives, la valeur de a >> b est la partie entière de a/2b
. Pour a négatif, la valeur de a >> b est définie par l'implémentation (dans la plupart des implémentations, ce décalage arithmétique effectue droit, de sorte que le résultat reste négatif)
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.
Dans tous les cas, si la valeur de l'opérande droit est négative, ou est supérieure ou égale au nombre de bits de l'opérande gauche promu, le comportement n'est pas défini .
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;unsignedlonglong 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 intlonglong ll =-1000;std::cout<<std::dec<<"-1000 >> 1 = "<<(ll >> ONE)<<'\n';}

Résultat :

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

[modifier]Bibliothèque standard

Les opérateurs arithmétiques sont surchargées pour de nombreux types de bibliothèques 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.

[modifier]Opérateurs arithmétiques unaires

met en œuvre + unaire et unaire -
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.

(fonction membre publique de std::chrono::duration)[edit]
s'applique opérateurs unaires aux nombres complexes
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.

(fonction générique)[edit]
applique un opérateur arithmétique unaire pour chaque élément 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.

(fonction membre publique de std::valarray)[edit]

[modifier]Opérateurs d'ajout

modifie le point de temps de la durée donnée
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.

(fonction générique)[edit]
concatène deux chaînes ou une chaîne et un char
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.

(fonction générique)[edit]
progrès de l'itérateur
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.

(fonction membre publique de std::reverse_iterator)
décrémente l'itérateur
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.

(fonction membre publique de std::reverse_iterator)
progrès de l'itérateur
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.

(fonction membre publique de std::move_iterator)
décrémente l'itérateur
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.

(fonction membre publique de std::move_iterator)
effectue l'arithmétique sur les nombres complexes deux valeurs complexes ou d'un complexe et un scalaire
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.

(fonction générique)[edit]
des opérateurs binaires s'applique à chaque élément de valarrays deux, ou un valarray et une valeur
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.

(fonction générique)[edit]

[modifier]Opérateurs de multiplication

met en œuvre des opérations arithmétiques avec des durées comme arguments
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.

(fonction générique)[edit]
effectue l'arithmétique sur les nombres complexes deux valeurs complexes ou d'un complexe et un scalaire
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.

(fonction générique)[edit]
des opérateurs binaires s'applique à chaque élément de valarrays deux, ou un valarray et une valeur
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.

(fonction générique)[edit]

[modifier]Opérateurs logiques bit à bit

effectue binaire AND, OR, XOR et 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.

(fonction membre publique de std::bitset)[edit]
effectue des opérations logiques binaires sur 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.

(fonction)[edit]
applique un opérateur arithmétique unaire pour chaque élément 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.

(fonction membre publique de std::valarray)
des opérateurs binaires s'applique à chaque élément de valarrays deux, ou un valarray et une valeur
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.

(fonction générique)

[modifier]Opérateurs de décalage au niveau du bit

des opérateurs binaires s'applique à chaque élément de valarrays deux, ou un valarray et une valeur
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.

(fonction générique)
effectue décalage binaire à gauche et déplacement vers la droite
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.

(fonction membre publique de std::bitset)

[modifier]Volet d'insertion / extraction opérateurs

Tout au long de la bibliothèque standard, les opérateurs de décalage au niveau du bit sont généralement surchargé par E / S courant (std::ios_base& ou l'une des classes dérivées de celle-ci) à la fois l'opérande gauche et le type de retour. Ces opérateurs sont connus sous le nom d'insertion flux' et' extraction flux: opérateurs
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.
extraits des données formatées
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.

(fonction membre publique de std::basic_istream)[edit]
extrait des tableaux de caractères et de caractères
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.

(fonction générique)[edit]
inserts en forme des données
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.

(fonction membre publique de std::basic_ostream)[edit]
insère des données de caractères
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.

(fonction)[edit]
sérialise et désérialise un nombre complexe
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.

(fonction générique)[edit]
effectue flux d'entrée et de sortie 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.

(fonction)[edit]
effectue des opérations d'entrée/sortie de flux sur des chaines de caractères
(fonction générique)[edit]
effectue flux d'entrée et de sortie sur le moteur de nombres pseudo-aléatoires
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.

(fonction)[edit]
effectue flux d'entrée et de sortie sur la distribution de nombre pseudo-aléatoire
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.

(fonction)[edit]

[modifier]Voir aussi

La priorité des opérateurs

Opérateurs ordinaires
affectationincrémentation
décrémentation
arithmétiquelogiquecomparaisonaccès aux membreautre

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
?:

Opérateurs spéciaux

static_cast convertit un type dans un autre type compatible

dynamic_cast convertit une classe de base virtuelle dans une classe dérivée

const_cast convertit un type dans un type compatible avec des cv-qualifiers différents

reinterpret_cast convertit un type dans un type incompatibles

new allocation de la mémoire

delete libère de la mémoire

sizeof récupère la taille d'un type

sizeof... récupère la taille d'un paquet de paramètres (depuis C++11)

typeid récupère les informations de type d'un type

noexcept vérifie si une expression peut lancer une exception (depuis C++11)

alignof récupère les conditions d'alignement d'un type (depuis C++11)

close