C/C++ の演算子

ID: 5
creation date: 2009/11/27 12:17
modification date: 2009/11/27 12:17
owner: taiji
tags: C,C++,operator

C++ の演算子をオーバーロードしたクラスを使っていると、演算子の本来の意味から乖離していたりすると、覚えているはずの演算子の優先順位が頭の中で混乱する場合があるので、今一度まとめてみた。

C/C++ の演算子と優先順位:

演算子 例 用途 結合 継承
:: x::y スコープ(Scope resolution) [C++ only] → x
++ -- x++ x-- 後置増分、減分(Postfix increment and decrement) ← o
() x(y) 関数呼出し(Function call) ← o
[] x[y] 配列添字(Array subscripting) ← o
. x.y ドット(Element selection by reference) ← x
-> x->y アロー(Element selection through pointer) ← o
++ -- ++x --y 前置増分、減分(Prefix increment and decrement) → o
+ - +x -x 単項正、負(Unary plus and minus) → o
& &x 単項アドレス(Address-of) → o
* *x 単項間接(Indirection) → o
! ~ !x ~x 論理否定、ビット否定 → o
() (x)y 型キャスト(Type cast) → o
sizeof sizeof x サイズ(Size-of) → x
new new[] new x new[] y 動的メモリ確保(Dynamic memory allocation) [C++ only] → o
delete delete[] delete x delete[] y 動的メモリ解放(Dynamic memory deallocation) [C++ only] → o
.* x.*y メンバへのポインタ(Pointer to member) [C++ only] → x
->* x->*y メンバへのポインタ(Pointer to member) [C++ only] → o
* / % x*y x/y x%y 二項乗、除、法(Multiplication,division,and modulus) → o
+ - x+y x-y 二項加、減(Addition and subtraction) → o
<< >> x<<y x>>y ビット左、右シフト(Bitwise left shift and right shift) → o
< <= x<y x<=y 関係不等号(Relational "less than" and "or equal to") → o
> >= x>y x>=y 関係不等号(Relational "greater than" and "or equal to") → o
== != x==y x!=y 関係等号、不等号(Relational "equal to" and "not equal to") → o
& x&y ビットAND(Bitwise AND) → o
^ x^y ビットXOR(Bitwise XOR) → o
| x|y ビットOR(Bitwise OR) → o
&& x&&y 論理AND(Logical AND) → *
|| x||y 論理OR(Logical OR) → *
? : x?y:z 三項条件(Ternary conditional) ← x
= x=y 単純代入(Direct assignment) ← o
+= -= x+=y 複合代入(Assignment by sum and difference) ← o
*= /= %= x*=y 複合代入(Assignment by product,quotient,and remainder) ← o
<<= >>= x<<=y 複合代入(Assignment by bitwise left shift and right shift) ← o
&= ^= |= x+=y 複合代入(Assignment by bitwise AND,XOR,and OR) ← o
, x,y コンマ(Comma) → *

てゆーか、手元でまとめてあったのを表組で投稿してみた。

0 コメント
ゲストコメント認証用なぞなぞ:
キーボードのLから左に全部打って下さい。それを二回やって下さい。 ...