short --> int --> unsigned int --> long --> unsigned long --> float --> double --> long double
#include <stdio.h>
void main(){
char c1 = ‘a‘;
int num1 = c1;
double d1 = num1;
short s1 = 10;
int num2 = 20;
int num3 = s1 + num2;
float f1 = 1.1f ;
double d2 = 4.24232346576;
f1 = d2 ;//出现精度损失
printf("f1=%.8f",f1);
getchar();
}
#include <stdio.h>
void main(){
double d1 = 1.978;
int num = (int)d1; //注意不是四舍五入,而是直接截断小数后的部分
//强制转换只对最近的数有效,如果希望针对更多的表达式转换,使用()
int num2 = (int)3.5 * 10 + 6 * 1.5;
int num3 = (int)(3.5*10+6*1.5);
printf("num3 = %d",num3);
printf("num = %d d1 = %f",num,d1);
getchar();
}
#include <stdio.h>
void main(){
char c = ‘a‘;
int i = 5;
float d = .231f;
double d2 = 1.0;
double result = c + i + d;
char result = c + i + d + d2;//出现警告
getchar();
}
原文:https://www.cnblogs.com/mx-info/p/14231968.html