1、新建項目
為了方便,我們新建一個Single View Application 。
輸入項目名稱 BaseType
Product Name: 指產品名稱 ,類似於項目名稱。
Company Identifier: 公司標識符,一般命名規則為 “com.公司名”
Bundle Identifier: 指包標識符,用於唯一標識應用程序,默認會根據公司標識符和產品名來組合生成
Device Family: 指該應用支持的設備類型,共三個選項:iPhone、iPad、Universal(即iPhone、iPad通用)
Include Unite Tests: 是否包含單元測試代碼模板,如果勾選,Xcode會幫助生成單元測試代碼模板
在項目裡找到,ViewController.m 為了方便演示,在界面啟動時,我們加入測試代碼
2 、C語言的基本數據類型長度
-
- NSLog(@"The size of an int is: %lu bytes.",sizeof(int));
- NSLog(@"The size of a short int is: %lu bytes.",sizeof(short int));
- NSLog(@"The size of a long int is: %lu bytes.",sizeof(long int));
- NSLog(@"The size of a char is: %lu bytes.",sizeof(char));
- NSLog(@"The size of a float is: %lu bytes.",sizeof(float));
- NSLog(@"The size of a double is: %lu bytes.",sizeof(double));
- NSLog(@"The size of a bool is: %lu bytes.",sizeof(bool)); // Do any additional setup after loading the view,
結果:
- 2012-06-13 13:55:46.726 BaseType[3032:f803] The size of an int is: 4 bytes.
- 2012-06-13 13:55:46.726 BaseType[3032:f803] The size of a short int is: 2 bytes.
- 2012-06-13 13:55:46.727 BaseType[3032:f803] The size of a long int is: 4 bytes.
- 2012-06-13 13:55:46.731 BaseType[3032:f803] The size of a char is: 1 bytes.
- 2012-06-13 13:55:46.732 BaseType[3032:f803] The size of a float is: 4 bytes.
- 2012-06-13 13:55:46.733 BaseType[3032:f803] The size of a double is: 8 bytes.
- 2012-06-13 13:55:46.733 BaseType[3032:f803] The size of a bool is: 1 bytes.
3、格式化輸出數據
- //整型
- int integerType = 5;
- //浮點型
- float floatType = 3.1415;
- //雙浮點型
- double doubleType = 2.2033;
- //短整型
- short int shortType = 200;
- //長整型
- long long int longlongType = 7758123456767L;
- //c語言字符串
- char * cstring = "this is a string!";
-
-
- //整型
- NSLog(@"The value of integerType = %d",integerType);
- //浮點型
- NSLog(@"The value of floatType = %.2f",floatType);
- //雙浮點型
- NSLog(@"The value of doubleType = %e",doubleType);
- //短整型
- NSLog(@"The value of shortType = %hi",shortType);
- //長整型
- NSLog(@"The value of longlongType = %lli",longlongType);
- //c語言字符串
- NSLog(@"The value of cstring = %s",cstring);
結果:
- 2012-06-13 14:06:18.757 BaseType[3215:f803] The value of integerType = 5
- 2012-06-13 14:06:18.757 BaseType[3215:f803] The value of floatType = 3.14
- 2012-06-13 14:06:18.758 BaseType[3215:f803] The value of doubleType = 2.203300e+00
- 2012-06-13 14:06:18.758 BaseType[3215:f803] The value of shortType = 200
- 2012-06-13 14:06:18.758 BaseType[3215:f803] The value of longlongType = 7758123456767
- 2012-06-13 14:06:18.758 BaseType[3215:f803] The value of cstring = this is a string!