Objective-C資料型別和表示式
阿新 • • 發佈:2019-02-16
4.1資料型別和常量
Objective-C提供了4中基本的資料型別:int 、float、double、char 。
Objective-C中,任何數字,單個字元或者字串通常成為常量。
在程式碼清單4-1中使用了基本的Objective-C資料型別
程式輸出:integerVar is 100#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { int integerVar = 100 ; float floatVar = 221.79 ; double doubleVar = 9.33e+12 ; char charVar = 'x'; NSLog(@"integerVar is %d",integerVar); NSLog(@"floatVar is %f",floatVar); NSLog(@"doubleVar is %e",doubleVar); NSLog(@"doubleVar is %g",doubleVar); NSLog(@"charVar is %c",charVar); } return 0; }
floatVar is 221.789993
doubleVar is 9.330000e+12
doubleVar is 9.33e+12
charVar is x
注意輸出的第二行 世界顯示的值是由具體使用的計算機系統決定的,原因在於計算機內部使用了特殊的方式表示數字。