-4 c
在从long到short分配时,LSB 2字节为0,其中MSB填充来自堆栈的func1()算法值的值.为什么会发生这种情况,为什么编译器试图将这些垃圾值转换为MSB 2字节?
#include <stdio.h>
unsigned short func1(void); // NB: function prototype !
int main(void)
{
unsigned long int L = 0;
unsigned short K = 0;
L = func1();
printf("%lu", L); // prints junk values
K = L;
printf("%u", K); // prints 0
return 0;
}
unsigned short func1(void)
{
unsigned short i = 0;
// Algorithm Logic!!!
return i; // returns 0
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1820 次 |
| 最近记录: |