김학규의 홈페이지입니다.
뉴스와토론
Neolith의 방
갤러리
기획&아이디어
Q&A와 스터디
소모임&잡담
차갤
지름신갤
추천/비추천
WIKI
링크
Q&A와 스터디
글 수
3,012
회원 가입
로그인
c++ 간단한 질문이요
김형근
http://old.lameproof.com/387870
2005.08.18
09:51:18 (*.97.38.21)
1225
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 (허용 확장자 : *.*)
번호
제목
글쓴이
날짜
조회 수
1032
게임 기획자 채용은..
3
DarkHos
2005-08-22
1137
1031
LPDIRECTDRAW7 관련 질문..
4
17
박현만
2005-08-22
1737
1030
보통 게임 개발자들은 일주일을 이나 하루를 어떻게 보내나요?
12
김성수
2005-08-21
1312
1029
제작,기획,개발등...설명좀 해주세요;
5
사기꾼
2005-08-21
1216
1028
홍익대 소프트웨어 게임학부와 청강대 게임디자인학부.. 어디가 더 좋을까요?
11
GhostMK
2005-08-20
1582
1027
del112.tmp 란 파일이 뭘까요?
3
개츠비
2005-08-19
1202
1026
영상 연출에 대해서 공부하고 싶은대..
4
CamilleBidan
2005-08-18
1282
c++ 간단한 질문이요
8
김형근
2005-08-18
1225
1024
저작권이라는게요
8
★~choin~☆
2005-08-18
1170
1023
군사 장비는 라이센스를 딸 필요가 없습니까?
9
14
DP군
2005-08-17
1537
1022
윈도우 xp 64bit 쓰시는분 계시나요.??
3
13
히스
2005-08-17
3579
1021
win32 sdk 도움말 파일..
4
박현만
2005-08-16
1226
1020
라스더원더러 질문입니다.
1
dc]워너필링
2005-08-16
1317
1019
싸이월드 조회수 늘리면 뭐 주나요?
4
임재현
2005-08-16
1204
1018
국내 PC패키지 게임,완전보안 방법은 없을까요?
15
낚였다
2005-08-16
1219
1017
패키지게임 판매방식&온라인게임 결제 방식에 대한 질문입니다.
7
DP군
2005-08-15
1243
1016
100 만원으로 살수 있는 컴퓨터 견적좀
8
호키
2005-08-15
1327
1015
게임기획자를 꿈인 사람입니다
14
장민호
2005-08-14
1349
1014
게임기획 관련 서적 질문
6
1
DarkHos
2005-08-14
1219
1013
현재 프로로 활동중이신 분들에게 설문조사 들어갑니다.
16
creation
2005-08-14
1063
목록
쓰기
첫 페이지
95
96
97
98
99
100
101
102
103
104
끝 페이지
제목
내용
제목+내용
댓글
이름
닉네임
아이디
태그
검색
취소
그 때문에 가장 오른쪽이 먼저 연산되는 거라고 볼 수 있겠네요.
또한 한 라인에서 같은 변수의 증가 연산자는 컴파일러마다 다른 결과를 보일 수 있습니다. 사용하지 않도록 주의하는것이
좋습니다.