C언어 강좌를 보면서
예제들을 하나씩 테스트해보고있는데요..
<형변환 (자동 형변환)> 여기에 나와있는 설명으로는
1000 (정수형 2Byte)와 500 (정수형 2Byte)를 곱하면
값이 50000으로 2Byte의 크기를 넘어서기때문에 (35535)
이상한 값이 출력된다고 되어있는데..
어째서 바른값이 나오는것이죠
%ld가 4Byte라서 그런가요?
그런데 또 자동형변환 방식에 따르면
제대로된 값이 출력되어서는안되는데... 아이러니하네요.. 꼭 알려주세요
-bash-2.05b$ cat > sizetest.c
#include <stdio.h>
void main()
{
printf("%ld\n", 1000 * 500);
printf("%ld\n", 1000L * 500);
}
-bash-2.05b$ ls
sizetest.c
-bash-2.05b$ gcc
gcc: no input files
-bash-2.05b$ gcc -o sizetest sizetest.c
sizetest.c: In function `main':
sizetest.c:3: warning: return type of `main' is not `int'
-bash-2.05b$ ls
sizetest sizetest.c
-bash-2.05b$ ./sizetest
500000
500000
-bash-2.05b$
ps. 이거대로 했는데...
http://csily.ttongfly.net/helpme.txt
뒤에 %f 로 출력해도 5/2 를 하면 2가 나와야한다고 나와있는데..
-bash-2.05b$ cat > mk.c
#include <stdio.h>
void main()
{
printf("%d\n", 5/2);
printf("%d\n", 5/2.0);
printf("%f\n", 5/2);
printf("%f\n", 5/2.0);
}
-bash-2.05b$ gcc -o mk mk.c
mk.c: In function `main':
mk.c:3: warning: return type of `main' is not `int'
-bash-2.05b$ ./mk
2
0
2.500000
2.500000
-bash-2.05b$