Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2122] printf()함수에서....
ntn [ntnpluso] 1118 읽음    2003-03-21 15:52
안녕하세요... 다름이 아니라 아래 프로그램에서 형변환은 알겠는데...

실수형을 정수형으로 출력할때나 정수형을 실수형으로 출력할때 결과값이 0이나 -값이 나와서

도저히 설명할수가 없습니다.

왜 값이 그렇게 나오는 것인지 아시는 분은 설명좀 해주세요...ㅠ.ㅠ

#include<stdio.h>

int main(void)
{
    printf("answer1 is the integer %d\n", 9/4);
    printf("answer2 is the real %f\n", 9/4);
    printf("answer3 is the integer %d\n", (double)(9/4));
    printf("answer4 is the real %f\n",(double)(9/4));
    printf("answer5 is the integer %d\n",(double)9/4);
    printf("answer6 is the real %f\n",(double)9/4);
    printf("answer7 is the integer %d\n",(double)9/(double)4);
    printf("answer8 is the real %f\n",(double)9/(double)4);
    printf("answer9 is the integer %d\n",17.0/3.0);
    printf("answer10 is the real %f\n",17.0/3.0);
    printf("answer11 is the integer %d\n",(int)(17.0/3.0));
    printf("answer12 is the real %f\n",(int)(17.0/3.0));
    printf("answer13 is the integer %d\n",(int)17.0/3.0);
    printf("answer14 is the real %f\n",(int)17.0/3.0);
    printf("answer15 is the integer %d\n",(int)17.0/(int)3.0);
    printf("answer16 is the real %f\n",(int)17.0/(int)3.0);

    return 0;
}

출력값은

2             
0.000000    <--문제의 부분
0    <--문제의 부분
2.000000
0    <--문제의 부분
2.250000
0    <--문제의 부분
2.250000
-1431655765    <--문제의 부분
5.666667
5
0.000000    <--문제의 부분
-1431655765    <--문제의 부분
5.666667
5
0.000000    <--문제의 부분

좋은 답변 부탁드립니다.

+ -

관련 글 리스트
2122 printf()함수에서.... ntn 1118 2003/03/21
2123     Re:printf()함수에서.... 불사새 1301 2003/03/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.