float f2,f1 = 123.125;
他们之间有什么不同?
float f1 = 123.125,f2;
如果我将代码编写为
float f1,f2 = 123.125
该程序将有不同的结果
这是完整的程序
float f2,f1 = 123.125;
//float f1 = 123.125,f2;
int i1,i2 = -150;
i1 = f1; //floating to integer
NSLog(@"%f assigned to an int produces %i",f1,i1);
f1 = i2; //integer to floating
NSLog(@"%i assigned to a float produces %f",i2,f1);
f1 = i2/100; //integer divided by integer
NSLog(@"%i divied by 100 prouces %f",i2,f1);
f2= i2/100.0; //integer divided by a float
NSLog(@"%i divied by 100.0 produces %f",i2,f2);
f2= (float)i2 /100; // type cast operator
NSLog(@"(float))%i divided by 100 produces %f",i2,f2);