김학규의 홈페이지입니다.
뉴스와토론
Neolith의 방
갤러리
기획&아이디어
Q&A와 스터디
소모임&잡담
차갤
지름신갤
추천/비추천
WIKI
링크
Q&A와 스터디
글 수
3,012
회원 가입
로그인
c++ 간단한 질문이요
김형근
http://old.lameproof.com/387870
2005.08.18
09:51:18 (*.97.38.21)
1222
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 (허용 확장자 : *.*)
조회 수
추천 수
날짜
최근 수정일
이런 것이 실제로 구현가능한지 여쭤보고 싶습니다.
(
6
)
모자장수
2005.08.06
조회 수
1461
추천 수
40
[re] 또다른의문
(
1
)
백두루
2003.08.13
조회 수
1945
추천 수
41
학규님 질문있습니다!
(
1
)
2B
2004.01.14
조회 수
1629
추천 수
41
IDC 서버 임대 비용
(
3
)
[
1
]
180업군
2004.05.27
조회 수
1476
추천 수
41
비디오게임...
(
9
)
Unfinished
2004.10.04
조회 수
1148
추천 수
41
psp언톨드 레전드 넷플레이 안되나요?
(
1
)
호키
2005.08.02
조회 수
1198
추천 수
41
MMORPG와 RPG란?
(
5
)
이슈레인
2005.08.03
조회 수
1325
추천 수
41
시놉시스,시나리오 어떻게..?
(
3
)
아렌시아
2005.08.13
조회 수
1212
추천 수
41
LPDIRECTDRAW7 관련 질문..
(
4
)
[
17
]
박현만
2005.08.22
조회 수
1736
추천 수
41
C언어
(
10
)
개츠비
2005.12.24
조회 수
2501
추천 수
41
온라인게임 프로그래머 분께 질문...
(
7
)
파루
2004.08.08
조회 수
1375
추천 수
42
그 시작프로그램에 없는데 시작할때뜨는 것들...
(
10
)
musashigun
2004.10.21
조회 수
1144
추천 수
42
사운드 드라이브 이상이 있습니다.
(
5
)
kimo
2005.03.30
조회 수
1121
추천 수
42
질문입니다-
(
1
)
★_zignight_★
2005.05.14
조회 수
1182
추천 수
42
모르는 용어에 대한 질문;;
(
12
)
박현만
2005.10.24
조회 수
1223
추천 수
42
나는 누구?
(
11
)
RpgMegaMix
2005.10.25
조회 수
1219
추천 수
42
DirectX Tutorial 05 ~ 07
1ststory
2005.07.20
조회 수
1551
추천 수
43
저기 프로그래밍 공부는..
(
12
)
강보성
2005.08.13
조회 수
1453
추천 수
43
c++ 간단한 질문이요
(
8
)
김형근
2005.08.18
조회 수
1222
추천 수
43
많은 선배님들의 조언 부탁드립니다.
(
2
)
로이뮤즈
2005.12.18
조회 수
1576
추천 수
43
목록
쓰기
첫 페이지
138
139
140
141
142
143
144
145
146
147
끝 페이지
제목
내용
제목+내용
댓글
이름
닉네임
아이디
태그
검색
취소
그 때문에 가장 오른쪽이 먼저 연산되는 거라고 볼 수 있겠네요.
또한 한 라인에서 같은 변수의 증가 연산자는 컴파일러마다 다른 결과를 보일 수 있습니다. 사용하지 않도록 주의하는것이
좋습니다.