Abh*_*hek 3 c logic type-conversion
鉴于此代码:
#include <stdio.h>
int main (void)
{
int x = 5;
double y = 6;
int z = x+y;
printf("size of z = %d bytes",sizeof(z));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
哪个逻辑正确描述了线路上发生的事情 - int z = x+y?
int为double添加它们时()z是类型int,所以它不会转换为doublez...是类型int!z属于类型int,所以它的大小是4个字节)要么
double为int添加它们时()隐式转换以下是来自www.tutorialspoint.com/cprogramming的图片,它将取代我的长答案:
"编译器首先执行整数提升,如果操作数仍然具有不同的类型,则它们将转换为在以下层次结构中显示最高的类型:"
