读书人

请问操作符

发布时间: 2012-03-22 17:43:57 作者: rapoo

请教操作符
#include "stdio.h "
main () {
int q,temp;
char apple;
temp = sizeof(int) * q;
apple = (char) temp;
printf( "The result is: %d\n ",apple);
}
输出0
#include "stdio.h "
main () {
int q,temp;
char apple;
temp =0;
q =10;
temp = sizeof(int) * q;
apple = (char) temp;
printf( "The result is: %d\n ",apple);
}
输出20
怎么一会事啊。请教 !

[解决办法]
#include "stdio.h "
main () {
int q,temp;
char apple;
temp =0;
q =10;
temp = sizeof(int) * q;
apple = (char) temp;
printf( "The result is: %d\n ",apple);
}
一般sizeof(int)=4或者2,要看编译器和系统,明显你这里是2所以出20
[解决办法]
TC2.0 是16位的,sizeof(int)=2,所以 apple=2*q=2*10=20

读书人网 >C语言

热点推荐