반응형
C언어 연산자 우선 순위에 관한 자료가 있어 가져왔다.
언어를 배우는데 가장 기초적인 부분이기는 하지만
또한 가끔 실수가 있는 부분이라서 여기서 문제가 생길경우에 많은 시간을 허비하게 되는 경우가 많다.
실력을 키우려면 기초부터 튼튼하게 다지자!
This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.
Operator |
Description |
Associativity |
---|---|---|
() [] . -> ++ -- |
Parentheses (function call) (see Note 1) Brackets (array subscript) Member selection via object name Member selection via pointer Postfix increment/decrement (see Note 2) |
left-to-right |
++ -- + - ! ~ (type) * & sizeof |
Prefix increment/decrement Unary plus/minus Logical negation/bitwise complement Cast (change type) Dereference Address Determine size in bytes |
right-to-left |
* / % | Multiplication/division/modulus | left-to-right |
+ - | Addition/subtraction | left-to-right |
<< >> | Bitwise shift left, Bitwise shift right | left-to-right |
< <= > >= |
Relational less than/less than or equal to Relational greater than/greater than or equal to |
left-to-right |
== != | Relational is equal to/is not equal to | left-to-right |
& | Bitwise AND | left-to-right |
^ | Bitwise exclusive OR | left-to-right |
| | Bitwise inclusive OR | left-to-right |
&& | Logical AND | left-to-right |
|| | Logical OR | left-to-right |
?: | Ternary conditional | right-to-left |
= += -= *= /= %= &= ^= |= <<= >>= |
Assignment Addition/subtraction assignment Multiplication/division assignment Modulus/bitwise AND assignment Bitwise exclusive/inclusive OR assignment Bitwise shift left/right assignment |
right-to-left |
, |
Comma (separate expressions) | left-to-right |
- Note 1:
- Parentheses are also used to group expressions to force a different order of evaluation; such parenthetical expressions can be nested and are evaluated from inner to outer
- Note 2:
- Postfix increment/decrement have high precedence, but the actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes execution). So in the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates to z) and z only incremented after all else is done. See postinc.c for another example.
반응형
'학습자료(~2017) > C,C++' 카테고리의 다른 글
GUN C Library (한글파일) (0) | 2012.01.10 |
---|---|
[윈도우] 윈도우 데이터 타입 Windows Data Types (0) | 2012.01.10 |
유니코드(unicode) 관련 함수 (0) | 2011.11.17 |
[WINAPI] 파일 경로 조작 api (1) | 2011.11.12 |
icon overlay 아이콘 오버레이 [펌 정리] (0) | 2011.11.10 |