이름공간
변수
행위

C++ 연산자 우선순위

cppreference.com
< cpp‎ | language
 
 
C++ 언어
General topics
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Initialization
Literals
Expressions
operators
operator precedence
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

아래의 테이블은 C++ 연산자들의 연결규칙과 우선순위입니다. 연산자는 위에서부터 아래로 내림차순의 우선순위를 가집니다.

The following table lists the precedence and associativity of C++ operators. Operators are listed top to bottom, in descending precedence.

우선순위 연산자 설명 결합방향
1 :: Scope resolution 좌 → 우
2 ++ -- 후위 증가와 감소
() 함수호출
[] 배열 첨자
. 참조로 요소 선택
-> 포인터를 통해 요소 선택
3 ++ -- 전위 증가와 감소 우 → 좌
+ 단항 부호 연산자
! ~ 논리 NOT, 비트단위 NOT
(type) 타입 캐스트
* 역참조
& 주소값
sizeof Size-of 연산자
new, new[] 동적 메모리 할당
delete, delete[] 동적 메모리 해제
4 .* ->* 멤버 포인터 접근 좌 → 우
5 * / % 곱셈, 나눗셈, 나머지
6 + 더하기, 빼기
7 << >> 비트 왼쪽 쉬프트와 오른쪽 쉬프트
8 < <= 관계 연산자 < 와 ≤
> >= 관계 연산자 > 와 ≥
9 == != 관계 = 와 ≠
10 & 비트 AND
11 ^ 비트 XOR (exclusive or)
12 | 비트 OR (inclusive or)
13 && 논리 AND
14 || 논리 OR
15 ?: 조건 연산자 (삼항 연산자) 우 → 좌
= 직접 할당 (C++ 클래스를 위해 기본 제공)
+= −= 합과 차 할당
*= /= %= 곱, 몫, 나머지 할당
<<= >>= 비트 왼쪽 쉬프트와 오른쪽 쉬프트 후 할당
&= ^= |= 비트연산 AND, XOR, OR 연산 후 할당
16 throw (예외를 위한)Throw 연산자
17 , 콤마 좌 → 우


When parsing an expression, an operator which is listed on some row will be bound tighter (as if by parentheses) to its arguments than any operator that is listed on a row further below it. For example, the expressions std::cout<<a&b and *p++ are parsed as (std::cout<<a)&b and *(p++), and not as std::cout<<(a&b) or (*p)++.

Operators that are in the same cell (there may be several rows of operators listed in a cell) are evaluated with the same precedence, in the given direction. For example, the expression a=b=c is parsed as a=(b=c), and not as (a=b)=c because of 우 → 좌 associativity.

An operator's precedence is unaffected by overloading.

[편집] Notes

The standard itself doesn't specify precedence levels. They are derived from the grammar.

const_cast, static_cast, dynamic_cast, reinterpret_cast and typeid are not included since they are never ambiguous.

Some of the operators have alternate spellings (e.g., and for &&, or for ||, not for !, etc.).

[편집] See also

Order of evaluation of operator arguments at run time.

일반 연산자
대입 증가
감소
산술 논리 비교 멤버
접근
기타

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 는 타입을 다른 호환 가능한 타입으로 변환합니다
dynamic_cast 는 가상 기반 클래스를 해당 클래스를 상속한 하위 클래스로 변환합니다.
const_cast 는 타입을 다른 cv 제한자를 가진 호환 가능한 타입으로 변환합니다.
reinterpret_cast 는 타입을 호환되지 않는 타입으로 변환합니다.
new 는 메모리를 할당합니다.
delete 는 할당된 메모리를 해제합니다.
sizeof 는 타입의 크기를 조회합니다.
sizeof...parameter pack 의 크기를 조회합니다.(since C++11)
typeid 는 타입 정보를 조회합니다.
noexcept 는 표현식이 예외(exception)을 던질 수 있는지 검사합니다. (since C++11)
alignof 는 타입이 요구하는 정렬법을 조회합니다. (since C++11)