May*_*ank 1 c unix shift bitwise-operators
Please explain the output of below program....
int main()
{
unsigned int i=0,j=0;
char c = 'J';
i = (unsigned int) c;
i|=(unsigned int) (c+1)<<8;
i|= (unsigned int) (c+2) <<16;
i|= (unsigned int) (c+3) <<24;
printf("\n%s",&i);
}
Run Code Online (Sandbox Code Playgroud)
以上程序的输出显示为JKLM请解释原因?
小智 7
Standardese挑剔答案:因为你的程序有不确定的行为.该%s转换说明需要一个char *或一个unsigned char *参数,但传递给它的unsigned int *.
后面的幕后回答:您的机器可能是小端,因此最低有效字节的内存地址最低.
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |