首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

请问操作符

2012-03-22 
请教操作符#includestdio.h main(){intq,tempcharappletempsizeof(int)*qapple(char)tempprintf(

请教操作符
#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

热点排行