Arithmetic operators
Aus cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Gibt das Ergebnis der spezifischen arithmetischen Operation .
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.
You can help to correct and verify the translation. Click here for instructions.
Operator name | Syntax | Overloadable | 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); |
|
Inhaltsverzeichnis |
[Bearbeiten] Erklärung
Alle arithmetischen Operatoren berechnen das Ergebnis der spezifischen arithmetischen Operation und liefert das Ergebnis. Die Argumente werden nicht geändert .
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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Conversions
Wenn der Operand übergeben eines arithmetischen Operators sind integrale oder ohne Bereichseinschränkung Aufzählungstyp, dann vor allen anderen Maßnahmen (aber nach lvalue-to-rvalue Umwandlung, falls zutreffend), erfährt der Operand ganzheitliche Förderung. Wenn ein Operand Array oder Funktionstyp, array-to-Zeiger und Funktion-to-Zeiger Konvertierungen angewendet werden .
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 ganzheitliche Förderung. 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.
You can help to correct and verify the translation. Click here for instructions.
Für die binären Operatoren (außer Verschiebungen), wenn die geförderten Operanden verschiedener Typen, zusätzliche Reihe von impliziten Konvertierungen angewendet wird, als üblichen arithmetischen Umwandlungen bekannt sind mit dem Ziel, zur Herstellung des häufigste Art (auch über Die std::common_type Typ-Trait)
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.
You can help to correct and verify the translation. Click here for instructions.
- Wenn einer der Operanden hat scoped Aufzählungstyp, wird keine Konvertierung durchgeführt: der andere Operand und der Rückgabetyp muss den gleichen Typ habenOriginal:If either operand has scoped enumeration type, no conversion is performed: the other operand and the return type must have the same typeThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Andernfalls, wenn einer der Operanden long double, wird der andere Operand long double umgewandeltOriginal:Otherwise, if either operand is long double, the other operand is converted to long doubleThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Andernfalls, wenn einer der Operanden double, wird der andere Operand double umgewandeltOriginal:Otherwise, if either operand is double, the other operand is converted to doubleThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Andernfalls, wenn einer der Operanden float, wird der andere Operand float umgewandeltOriginal:Otherwise, if either operand is float, the other operand is converted to floatThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Ansonsten hat der Operand vom Typ Integer (weil bool, char, char16_t, char32_t, wchar_t und ohne Bereichseinschränkung Aufzählung an dieser Stelle gefördert wurden) und integraler Konvertierungen angewendet werden, um die häufigste Art produzieren, wie folgt: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 integraler Konvertierungen 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.
- Wenn beide Operanden signiert sind oder beide sind unsigniert, der Operand mit geringerer Umwandlung Rang wird dem Operanden mit dem größeren Ganzzahlumwandlung Rang umgewandeltOriginal: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 rankThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Andernfalls, wenn der vorzeichenlosen Operanden Bekehrung Rang größer oder gleich der Umwandlung Rang des unterzeichneten Operanden, ist das unterzeichnete Operanden der unsigned Operanden konvertiert .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.
-
- Ansonsten, wenn das unterzeichnete Operanden den Typ alle Werte des vorzeichenlosen Operanden darstellen kann, wird die vorzeichenlosen Operanden des Unterzeichners Operanden konvertiertOriginal: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 typeThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
-
- Ansonsten werden beide Operanden dem unsigned Pendant des unterzeichneten Operanden konvertiert .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.
-
Das Umwandlung Rang oben steigt, um bool, signed char, short, int, long, long long. Der Rang eines unsigned Typ ist gleich dem Rang des entsprechenden Datentyp mit Vorzeichen. Der Rang der char ist gleich dem Rang signed char und unsigned char. Die Reihen der char16_t, char32_t und wchar_t gleich den Reihen ihrer zugrunde liegenden Typen .
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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Überläuft
Unsigned Ganzzahlarithmetik immer modulo 2n
wobei n die Anzahl der Bits in diesem bestimmten ganzzahligen durchgeführt. Z.B. für unsigned int, indem man UINT_MAX gibt 0 und Subtrahieren von eins von 0 gibt UINT_MAX .
wobei n die Anzahl der Bits in diesem bestimmten ganzzahligen durchgeführt. Z.B. für unsigned int, indem man UINT_MAX gibt 0 und Subtrahieren von eins von 0 gibt 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.
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.
You can help to correct and verify the translation. Click here for instructions.
Wenn Ganzzahl arithmetische Operation überläuft (das Ergebnis nicht in der Ergebnis-Typ passen), das Verhalten undefiniert ist: es kann sich um nach den Regeln der Darstellung (in der Regel 2-Komplement) wickeln, kann es auf einigen Plattformen oder durch Compiler abzufangen Optionen (zB
-ftrapv
in GCC und Clang), oder kann vollständig optimized out by the compiler sein .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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Unäre arithmetische Operatoren
Für jeden gefördert arithmetischen Typ
A
und für jede Art T
, beteiligen die folgende Funktion Signaturen in Überlast-Auflösung: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.
You can help to correct and verify the translation. Click here for instructions.
A operator+(A) |
||
T* operator+(T*) |
||
A operator-(A) |
||
Der eingebaute unären Plus-Operator gibt den Wert seines Operanden. Die einzige Situation, in der sie keine No-op ist, wenn der Operand integralen Typ oder ohne Bereichseinschränkung Enumerationstyp, die von integralen Förderung geändert wird, zB, wandelt es zu char int oder wenn der Operand unter Lvalue-zu-R-Wert, array-to-pointer oder Funktion-to-Zeiger Umwandlung .
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.
You can help to correct and verify the translation. Click here for instructions.
Der eingebaute unären Minus-Operator berechnet den negativen seines Operanden. Für unsigned
-a, wo
a
, ist der Wert der -a
2b-a, wo
b
die Anzahl der Bits nach dem Aufstieg ist .Original:
The builtin unary minus operator calculates the negative of its operand. For unsigned
-a, where
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.
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
[Bearbeiten] Additive Operatoren
Für jedes Paar von geförderten arithmetische Typen
L
und R
und für jeden Objekttyp T
, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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.
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*) |
||
wo
LR
ist das Ergebnis der üblichen arithmetischen Umwandlungen auf L
und 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.
You can help to correct and verify the translation. Click here for instructions.
Mit Operanden arithmetischen oder Enumerationstyp, das Ergebnis der binären zuzüglich der Summe der Operanden (nach üblichen arithmetischen converesions), und das Ergebnis der binären Minusoperator ist das Ergebnis der Subtraktion des zweiten Operanden aus dem ersten (nach üblichen arithmetischen Konvertierungen ) .
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.
You can help to correct and verify the translation. Click here for instructions.
Wenn einer der Operanden ein Zeiger ist, gelten die folgenden Regeln:
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.
You can help to correct and verify the translation. Click here for instructions.
- Ein Zeiger auf Nicht-Array Objekt als ein Zeiger auf das erste Element eines Array mit Größe 1 behandelt .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. - Wenn der Zeiger zeigt auf die
P
i
th Element eines Arrays, werden die AusdrückeP+n
,n+P
undP-n
sind Zeiger des gleichen Typs, die auf diei+n
th,i+n
th undi-n
th Element desselben Array sind. Das Ergebnis der Zeiger Zusätzlich kann auch ein ein-Vorbeireden Endzeiger sein (dh ZeigerP
so dass die ExpressionP-1
zeigt auf das letzte Element des Arrays). Jede andere Situationen (das heißt, versucht, einen Zeiger, der nicht in die Richtung unter einem Element der gleichen Array oder ein über das Ende zu erzeugen) aufzurufen undefinierten Verhalten .Original:If the pointerP
points to thei
th element of an array, then the expressionsP+n
,n+P
, andP-n
are pointers of the same type that point to thei+n
th,i+n
th, andi-n
th element of the same array, respectively. The result of pointer addition may also be a one-past-the-end pointer (that is, pointerP
such that the expressionP-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. - Wenn der Zeiger zeigt auf die
P
i
th Element eines Arrays, und der ZeigerQ
Punkten amj
th Element des gleichen Array weist die ExpressionP-Q
den Wert i-j, wenn der Wert passt std::ptrdiff_t. Beide Operanden muss den Elementen desselben Array (oder ein über das Ende) hinweisen, sonst nicht definiert. Wenn das Ergebnis nicht in std::ptrdiff_t passen, ist das Verhalten undefiniert .Original:If the pointerP
points to thei
th element of an array, and the pointerQ
points at thej
th element of the same array, the expressionP-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. - Wenn der Wert 0 addiert oder subtrahiert wird von einem Zeiger, ist das Ergebnis der Zeiger, unverändert. Wenn zwei Zeiger, auf gleicher Objekt oder sowohl ein über das Ende des gleichen Array oder beide Null-Zeiger, dann ist das Ergebnis der Subtraktion sind gleich (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.
Diese Pointer-Arithmetik-Operatoren erlauben Zeiger auf die
RandomAccessIterator
Konzept zu erfüllen .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.
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
[Bearbeiten] Multiplikativen Operatoren
Für jedes Paar von geförderten arithmetische Typen
LA
und RA
und für jedes Paar gefördert ganzzahligen Typen LI
und RI
die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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.
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) |
||
wo
LRx
ist das Ergebnis der üblichen arithmetischen Umwandlungen auf Lx
und 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.
You can help to correct and verify the translation. Click here for instructions.
Der binäre Operator * führt Multiplikation der Operanden (nach üblichen arithmetischen Umwandlungen) .
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.
You can help to correct and verify the translation. Click here for instructions.
Der binäre Operator / teilt den ersten Operanden durch den zweiten (nach üblichen arithmetischen Umwandlungen). Wenn der zweite Operand null ist, das Verhalten undefiniert ist. Für ganzzahlige Operanden, liefert es den algebraischen Quotienten
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.
You can help to correct and verify the translation. Click here for instructions.
- abgerundet durch die Implementierung definiert Richtung (bis C + +11)Original:rounded in implementation-defined direction (bis C + +11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - mit jedem Bruchteil verworfen (Richtung Null abgeschnitten) (seit C++11)Original:with any fractional part discarded (truncated towards zero) (seit C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Der binäre Operator% liefert den Rest der Division des ersten Operanden durch den zweiten (nach der üblichen arithmetischen Umwandlungen). Ist der Quotient
a/b
representible in der Ergebnis-Typ, (a/b)*b + a%b == a. Wenn der zweite Operand gleich null ist, ist das Verhalten undefiniert .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.
You can help to correct and verify the translation. Click here for instructions.
- wenn eine oder beide Operanden negativ sind, ist das Vorzeichen des Rests Implementierung definiert, wie es auf der Rundung Richtung Ganzzahldivision (bis C + +11) abhängtOriginal: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 (bis 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
[Bearbeiten] Bitweise logische Operatoren
Für jedes Paar von geförderten ganzzahligen Typen
L
und R
die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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.
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) |
||
wo
LR
ist das Ergebnis der üblichen arithmetischen Umwandlungen auf L
und 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.
You can help to correct and verify the translation. Click here for instructions.
Das Ergebnis der Operator ~ ist das bitweise NOT (Einerkomplement) Wert des Arguments (nach Promotion). Das Ergebnis der Operator & das binäre UND-Wert der Operanden (nach üblichen arithmetischen Umwandlungen). Das Ergebnis des Operators
Original:
das bitweise OR-Wert der Operanden (nach üblichen arithmetischen Umwandlungen). Das Ergebnis der Operator ^ das bitweise XOR-Wert der Operanden (nach üblichen arithmetischen Umwandlungen)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#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
[Bearbeiten] Operatoren für bitweise Verschiebung
Für jedes Paar von geförderten ganzzahligen Typen
L
und R
, die folgende Funktion Signaturen in Überladungsauflösung teilnehmen: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.
You can help to correct and verify the translation. Click here for instructions.
L operator<<(L, R) |
||
L operator>>(L, R) |
||
Die Operanden der eingebauten Operatoren für bitweise Verschiebung haben entweder integrale Typen oder ohne Bereichseinschränkung Aufzählungstyp. Integral Aktionen auf beiden Operanden vor der Auswertung durchgeführt. Der Rückgabetyp ist der Typ des linken Operanden nach integal Promotionen .
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.
You can help to correct and verify the translation. Click here for instructions.
Für unsigned
ist, reduziert modulo Maximalwert der Rückgabetyp plus 1 (das heißt, bitweise Verschiebung nach links durchgeführt wird, und die Bits, die aus dem Zieltyp bekommen verschoben werden verworfen). Für signierte
ist, wenn es darstellbar durch die Rückkehr Typ ist, da sonst das Verhalten nicht definiert .
a
der Wert a << b
der Wert a * 2bist, reduziert modulo Maximalwert der Rückgabetyp plus 1 (das heißt, bitweise Verschiebung nach links durchgeführt wird, und die Bits, die aus dem Zieltyp bekommen verschoben werden verworfen). Für signierte
a
der Wert a << b
a * 2bist, wenn es darstellbar durch die Rückkehr Typ ist, da sonst das Verhalten nicht definiert .
Original:
For unsigned
, 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
if it is representable by the return type, otherwise the behavior is undefined.
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 * 2bif 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.
You can help to correct and verify the translation. Click here for instructions.
Für unsigned
. Für negative
a
und unterschrieben a
mit nichtnegativen Werten, ist der Wert der a >> b
der Integer-Teil a/2b. Für negative
a
, ist der Wert der a >> b
Implementierung definiert (in den meisten Implementierungen, führt diese arithmetische Rechtsverschiebung, so dass das Ergebnis negativ ist)Original:
For unsigned
. For negative
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.
You can help to correct and verify the translation. Click here for instructions.
In jedem Fall, wenn der Wert des rechten Operanden negativ oder größer oder gleich der Anzahl von Bits in der linken Operanden befördert, ist das Verhalten undefiniert .
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.
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
[Bearbeiten] Standard-Bibliothek
Arithmetische Operatoren werden für viele Standard-Bibliothek Typen überlastet .
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.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Unäre arithmetische Operatoren
implementiert unäres + und unäres -. (öffentliche Elementfunktion of std::chrono::duration )
| |
gilt unären Operatoren zu komplexen Zahlen 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. (Funktions-Template) | |
gilt eine unäre arithmetische Operator für jedes Element des 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. (öffentliche Elementfunktion of std::valarray )
|
[Bearbeiten] Additive Operatoren
modifiziert den Zeitpunkt von der gegebenen Dauer 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. (Funktions-Template) | |
zwei Strings verkettet oder ein String und ein 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. (Funktions-Template) | |
Fortschritte der Iterator 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. (öffentliche Elementfunktion of std::reverse_iterator )
| |
Verringert den Iterator 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. (öffentliche Elementfunktion of std::reverse_iterator )
| |
Fortschritte der Iterator 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. (öffentliche Elementfunktion of std::move_iterator )
| |
Verringert den Iterator 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. (öffentliche Elementfunktion of std::move_iterator )
| |
führt komplexe Zahl Arithmetik auf zwei komplexe Werte oder eine komplexe und einem Skalar 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. (Funktions-Template) | |
gilt Binäroperatoren auf jedes Element von zwei valarrays oder ein valarray und einem Wert 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. (Funktions-Template) |
[Bearbeiten] Multiplikativen Operatoren
implementiert arithmetische Operationen mit Zeitintervallen als Argumente. (Funktions-Template) | |
führt komplexe Zahl Arithmetik auf zwei komplexe Werte oder eine komplexe und einem Skalar 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. (Funktions-Template) | |
gilt Binäroperatoren auf jedes Element von zwei valarrays oder ein valarray und einem Wert 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. (Funktions-Template) |
[Bearbeiten] Bitweise logische Operatoren
führt binäre AND, OR, XOR und 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. (öffentliche Elementfunktion of std::bitset )
| |
führt binäre Verknüpfungen auf BitSets aus 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. (Funktion) | |
gilt eine unäre arithmetische Operator für jedes Element des 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. (öffentliche Elementfunktion of std::valarray )
| |
gilt Binäroperatoren auf jedes Element von zwei valarrays oder ein valarray und einem Wert 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. (Funktions-Template) |
[Bearbeiten] Operatoren für bitweise Verschiebung
gilt Binäroperatoren auf jedes Element von zwei valarrays oder ein valarray und einem Wert 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. (Funktions-Template) | |
führt binäre Verschiebung nach links und rechts schieben 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. (öffentliche Elementfunktion of std::bitset )
|
[Bearbeiten] Stream Einfügen / Ausgabe-Operatoren
Während der gesamten Standard-Bibliothek werden bitweise Verschiebung Betreibern gemeinsam mit I / O-Strom (std::ios_base& oder einem der davon abgeleiteten Klassen) als sowohl der linken Operanden und Rückgabetyp überlastet. Solche Operatoren sind als Stream Insertion bekannt und Stream Extraktion Operatoren:
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.
You can help to correct and verify the translation. Click here for instructions.
Extrakte formatierte Daten 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. (öffentliche Elementfunktion of std::basic_istream )
| |
extrahiert Zeichen und Zeichen-Arrays 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. (Funktions-Template) | |
Einsätze formatierte Daten 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. (öffentliche Elementfunktion of std::basic_ostream )
| |
Einsätze Zeichendaten 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. (Funktion) | |
serialisiert und deserialisiert eine komplexe Zahl 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. (Funktions-Template) | |
für Ein- bzw. Ausgabe des BitSets über Streams 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. (Funktion) | |
führt Stream I / O on Strings 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. (Funktions-Template) | |
führt Stream Ein-und Ausgang auf Pseudo-Zufallszahlen-Motor 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. (Funktion) | |
Stream führt Eingabe und Ausgabe auf Pseudozufallszahl Verteilung 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. (Funktion) |
[Bearbeiten] Siehe auch
Common operators | ||||||
---|---|---|---|---|---|---|
Zuweisungen | incrementNJdecrement | Arithmetik | logisch | Vergleich | memberNJaccess | andererseits |
a = b |
++a |
+a |
!a |
a == b |
a[b] |
a(...) |
Special operators | ||||||
static_cast wandelt einem Typ in einen anderen kompatiblen Typ
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 wandelt virtuellen Basisklasse abgeleitet class
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 wandelt Typ kompatiblen Typ mit unterschiedlichen cv qualifiers
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. reinterpret_cast wandelt Typ inkompatibel type
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 ordnet 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 freigibt 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 fragt die Größe eines 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... fragt die Größe eines Parameter Pack (seit C++11)
Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. typeid fragt die Typinformationen eines 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 prüft, ob ein Ausdruck eine Ausnahme (seit C++11)
werfen kann Original: The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. alignof Abfragen Ausrichtungsanforderungen eines Typs (seit C++11)
Original: alignof queries alignment requirements of a type (seit C++11) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |