|
안녕하세요... 다름이 아니라 아래 프로그램에서 형변환은 알겠는데...
실수형을 정수형으로 출력할때나 정수형을 실수형으로 출력할때 결과값이 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 <--문제의 부분
좋은 답변 부탁드립니다.
|