김학규의 홈페이지입니다.
뉴스와토론
Neolith의 방
갤러리
기획&아이디어
Q&A와 스터디
소모임&잡담
차갤
지름신갤
추천/비추천
WIKI
링크
Q&A와 스터디
글 수
3,012
회원 가입
로그인
c++ 간단한 질문이요
김형근
http://old.lameproof.com/387870
2005.08.18
09:51:18 (*.97.38.21)
1220
43
/
0
void main()
{
int a=10;
cout<<a++<<a++<<a++;
}
이것의 결과값은 121110 입니다.
101112 가 아니고 121110 이유가 뭐에요?
이 게시물을...
목록
2005.08.18
10:23:56 (*.117.66.101)
shadowisle
위 소스에서 유의할 것은 << 라는 연산자 입니다. 이 연산자는 오른쪽이 연산 우위에 있을 겁니다. 마치 "=" 처럼 말이죠.
그 때문에 가장 오른쪽이 먼저 연산되는 거라고 볼 수 있겠네요.
또한 한 라인에서 같은 변수의 증가 연산자는 컴파일러마다 다른 결과를 보일 수 있습니다. 사용하지 않도록 주의하는것이
좋습니다.
2005.08.18
13:05:42 (*.94.41.89)
없음
일단, 위와 같은 프로그래밍은 잘못된 것입니다.
그 결과는 컴파일러의 implementation에 따라 다릅니다.
gcc 3.3.5에서는 101112 가 나옵니다. 따라서 이런 식의 모호한 프로그래밍은 피하셔야 합니다.
2005.08.18
13:14:43 (*.97.38.21)
김형근
이런식으로 사용하는 사람은 없겠지요. 참을 수 없는 호기심 이었습니다. 답변 감사드립니다.
2005.08.18
13:38:37 (*.117.66.101)
shadowisle
흠.. 같은 gcc에서도 다른 결과가 나오는군요.
gcc 3.3.1과 3.3.4에서는 121110이 나왔는데...
2005.08.18
13:38:45 (*.86.84.21)
1ststory
C에서는 <<의 연산은 좌에서 우로
++의 연산은 우에서 좌로 계산하게 됩니다.
++의 연산우선순위가 << 보다 높은 관계로 우측에 있는 것부터 계산하게 된 것 같군요.
정확한 결과를 원하시면 ( )로 감싸 주셔야 할 겁니다.
집이 아니라서 정확한 확인은 못하겠군요 -ㅅ-
2005.08.18
15:49:44 (*.106.218.187)
매지
cout<<a++<<a++<<a++;
풀어보면 cout.operator<<(a++).operator<<(a++).operator<<(a++);
풀어써도 결과는 똑같군요.
2005.08.18
16:49:41 (*.94.41.89)
없음
저는 cygwin의 g++ 3.3.4에서 테스트 해봐도 101112가 나옵니다. (앞에서 테스트 한 것은 linux(Debian)의 g++이었습니다)
2005.08.18
18:37:33 (*.117.66.101)
shadowisle
흠.. 제가 테스트 한 것은 g++ 3.3.1 (SuSE Linux 8.0), g++ 3.3.4 (SuSE Linux 9.2)... 과연 무슨 일이 있기에...
나의 소셜 정보
원하시는 로그인을 선택해주세요
비밀번호
» 편집 도구모음 건너뛰기
되돌리기
다시 실행
형식
제목 1
제목 2
제목 3
제목 4
제목 5
제목 6
글꼴
돋움
굴림
바탕
Arial
Arial Black
Tahoma
Verdana
Sans-serif
Serif
Monospace
Cursive
Fantasy
크기
9px
10px
11px
12px
13px
14px
16px
18px
24px
32px
줄 간격
100%
120%
140%
160%
180%
200%
진하게
밑줄
기울임
취소선
글자 색
#ff0000
#ff6c00
#ffaa00
#ffef00
#a6cf00
#009e25
#00b0a2
#0075c8
#3a32c3
#7820b9
#ef007c
#000000
#252525
#464646
#636363
#7d7d7d
#9a9a9a
#ffe8e8
#f7e2d2
#f5eddc
#f5f4e0
#edf2c2
#def7e5
#d9eeec
#c9e0f0
#d6d4eb
#e7dbed
#f1e2ea
#acacac
#c2c2c2
#cccccc
#e1e1e1
#ebebeb
#ffffff
#e97d81
#e19b73
#d1b274
#cfcca2
#cfcca2
#61b977
#53aea8
#518fbb
#6a65bb
#9a54ce
#e573ae
#5a504b
#767b86
#00ffff
#00ff00
#a0f000
#ffff00
#951015
#6e391a
#785c25
#5f5b25
#4c511f
#1c4827
#0d514c
#1b496a
#2b285f
#45245b
#721947
#352e2c
#3c3f45
#00aaff
#0000ff
#a800ff
#ff00ff
글자 배경색
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
가나다
위 첨자
아래 첨자
왼쪽 정렬
가운데 정렬
오른쪽 정렬
양쪽 정렬
번호 매기기
목록
단락의 들여쓰기 수준을 낮춥니다.
들여쓰기
인용문
왼쪽 실선
인용 부호
실선
실선 + 배경
굵은 실선
점선
점선 + 배경
적용 취소
링크
하이퍼링크
새 창으로
확인
취소
특수문자
특수문자 삽입
특수문자 레이어 닫기
일반기호
숫자와 단위
원, 괄호
한글
그리스,라틴어
일본어
선택한 기호
특수문자 레이어 닫기
표
칸 수 지정
행
1행 추가
1행 삭제
열
1열 추가
1열 삭제
표 속성 지정
테두리 굵기
1px 더하기
1px 빼기
테두리 색
색상 찾기
색상 찾기
표 배경색
색상 찾기
색상 찾기
셀 병합
열 분할
행 분할
확장 컴포넌트
이모티콘 출력
이미지 추가
멀티미디어 자료 관리
설문조사 컴포넌트
기본 이미지 갤러리
Naver Photo Editor
HTML 편집기
입력창 크기 조절
파일 첨부
선택 삭제
본문 삽입
문서 첨부 제한 : 0Byte/ 20.00MB
파일 제한 크기 : 20.00MB (허용 확장자 : *.*)
번호
제목
글쓴이
날짜
조회 수
2872
게임관련 학과
6
Unknown
2004-09-29
1144
2871
인터넷 익스플로러 관련
3
능구렁10단
2004-06-02
1184
2870
바이러스는 아닌거같은데.. 문제가 생겼습니다.
6
New.군39세
2004-05-26
1319
2869
회사에 대한 질문입니다.
2
견우
2005-10-22
1228
2868
라스더원더러 질문입니다.
1
dc]워너필링
2005-08-16
1311
2867
게임기획에서 사람다루는 기술이 많이 중요한가요?
6
creation
2005-08-10
1294
2866
2000 관련.. 도와주세요 ㅠ_ㅠ
4
카나에
2004-05-30
1299
2865
DirectX에서 말이죠..
2
10
1ststory
2005-07-11
1739
2864
비주얼c++ 완전초보가 물어보는 질문 답변좀 ..
14
1
sa
2005-12-26
1285
2863
동영상 인코딩 질문
1
카나에
2005-10-12
1358
2862
패키지게임 판매방식&온라인게임 결제 방식에 대한 질문입니다.
7
DP군
2005-08-15
1236
2861
타블렛 질문요 ;_;
2
-_-
2005-07-22
1159
2860
많은 선배님들의 조언 부탁드립니다.
2
로이뮤즈
2005-12-18
1572
c++ 간단한 질문이요
8
김형근
2005-08-18
1220
2858
저기 프로그래밍 공부는..
12
강보성
2005-08-13
1452
2857
DirectX Tutorial 05 ~ 07
1ststory
2005-07-20
1550
2856
나는 누구?
11
RpgMegaMix
2005-10-25
1216
2855
모르는 용어에 대한 질문;;
12
박현만
2005-10-24
1221
2854
질문입니다-
1
★_zignight_★
2005-05-14
1180
2853
사운드 드라이브 이상이 있습니다.
5
kimo
2005-03-30
1118
목록
쓰기
첫 페이지
3
4
5
6
7
8
9
10
11
12
끝 페이지
제목
내용
제목+내용
댓글
이름
닉네임
아이디
태그
검색
취소
그 때문에 가장 오른쪽이 먼저 연산되는 거라고 볼 수 있겠네요.
또한 한 라인에서 같은 변수의 증가 연산자는 컴파일러마다 다른 결과를 보일 수 있습니다. 사용하지 않도록 주의하는것이
좋습니다.