Post Increment/Decrement
Coddy Java 여정의 기초 섹션에 포함된 레슨 — 73개 중 18번째.
증가(++)와 감소(--) 연산자는 두 가지 방법으로 사용할 수 있습니다:
전위 증가/감소 (++x 또는 --x):
- 연산자가 변수 앞에 위치합니다
- 값이 즉시 변경됩니다
새 값이 표현식에서 사용됩니다
int x = 5; int y = ++x; // x is increased to 6 first, then y becomes 6
후행 증가/감소 (x++ 또는 x--):
- 연산자가 변수 뒤에 위치합니다
- 원래 값이 먼저 사용됩니다
값은 표현식 이후에 변경됩니다
int x = 5; int y = x++; // y becomes 5 first, then x increases to 6
또 다른 예제
후위 증분:
int score = 5;
int res1 = score++;
// res1 is 5
// score is 6전위 증가:
int score = 5;
int result2 = ++score;
// result2 is 6
// score is 6치트 시트
증가 연산자 (++)와 감소 연산자 (--)는 두 가지 방식으로 사용할 수 있습니다:
전위 증가/감소 (++x 또는 --x):
- 연산자가 변수 앞에 위치합니다
- 값이 즉시 변경됩니다
- 새 값이 표현식에서 사용됩니다
int x = 5;
int y = ++x;
// x is increased to 6 first, then y becomes 6후위 증가/감소 (x++ 또는 x--):
- 연산자가 변수 뒤에 위치합니다
- 원래 값이 먼저 사용됩니다
- 값이 표현식 이후에 변경됩니다
int x = 5;
int y = x++;
// y becomes 5 first, then x increases to 6직접 해보기
이 레슨에는 코드 챌린지가 없습니다.
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
기초의 모든 레슨
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 43Variables Part 2
ConstantsNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else