3.3 자체 증가 / 자체 감소 연산 자, 그리고 Side effects
3688 단어 effect
하나의 변 수 는 1 을 늘 리 는 것 과 1 을 줄 이 는 것 이 이렇게 평범 해서 C 에서 자신의 조작 자 를 가지 게 되 었 다.모든 조작 자 는 접두사 와 접두사 두 가지 버 전이 있다.
Operator
Symbol
Form
Operation
Prefix increment
++
++x
Increment x, then evaluate x
Prefix decrement
––
––x
Decrement x, then evaluate x
Postfix increment
++
x++
Evaluate x, then increment x
Postfix decrement
––
x––
Evaluate x, then decrement x
예:
1: int x = 5;
2: int y = ++x; // x is now equal to 6, and 6 is assigned to y
1: int x = 5;
2: int y = x++; // x is now equal to 6, and 5 is assigned to y
다시 한 번 예 를 들 어 전치 와 전치 사이 의 차 이 를 표시 합 니 다.
1: int x = 5, y = 5;
2: cout << x << " " << y << endl;
3: cout << ++x << " " << --y << endl; // prefix
4: cout << x << " " << y << endl;
5: cout << x++ << " " << y-- << endl; // postfix
6: cout << x << " " << y << endl;
결 과 는:
5 5
6 4
6 4
6 4
7 3
Side effects
A side effect is a result of an operator, expression, statement, or function that presists even after the operator, expression, statement, or function has finished being evaluated.
(표현 식, 함수, 구문 등 값 을 구 한 결과 로 해석 할 수 있 습 니까?)
예:
1: x = 5;
쓸모 가 있다.
그리고:
1: int x = 5;
2: int nValue = Add(x, ++x);
C + + 는 함수 에서 어떤 인자 가 먼저 값 을 구 하 는 지 정의 하지 않 았 습 니 다.두 가지 결과 가 발생 할 수 있 습 니 다. 1. Add (5, 6) 2、Add(6,6).
유사 한 결 과 를 일 으 킬 수 있 는 조작 자 를 사용 하지 않 는 것 이 일반적인 규칙 이다.모든 할당 연산 자, 자체 증가, 자체 감소.side effect 를 일 으 킬 수 있 는 조작 부 호 는 독립 된 문장 에 넣 어야 하기 때 문 입 니 다.
누가 side effects 를 설명 할 수 있 습 니까?
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Javascript의 매트릭스(및 펄리시) 배경 효과 :)오늘은 쓸데없지만 멋진 것을 보여드리려고 합니다. 내 매트릭스 펄리쉬 배경! 😎 😎 😎 내 github 페이지를 확인하여 😀 그것은 또는 에서 찾을 수 있는 작업에서 파생된 자바스크립트의 두 줄에 불과하므로 크레딧이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.