Objective C之基本資料型別

2021-09-18 04:12:12 字數 2404 閱讀 1040

//整型

int integertype = 5;

//浮點型

float floattype = 3.1415;

//雙浮點型

double doubletype = 2.2033;

//短整型

short int shorttype = 200;

//長整型

long int longlongtype = 7758123456767l;

//c語言字串

char * cstring = "this is a string!";

// 4位元組

nslog(@"the size of an int is: %ld bytes",sizeof(int));

//2位元組

nslog(@"the size of an short int is: %ld bytes",sizeof(short int));

//8位元組

nslog(@"the size of an long int is: %ld bytes",sizeof(long int));

//1位元組

nslog(@"the size of an char is: %ld bytes",sizeof(char));

//4位元組

nslog(@"the size of an float is: %ld bytes",sizeof(float));

//8位元組

nslog(@"the size of an double is: %ld bytes",sizeof(double));

//1位元組

nslog(@"the size of an bool is: %ld bytes",sizeof(bool));

//整型

nslog(@"the value of integertype = %d.",integertype);

//浮點型

nslog(@"the value of integertype = %.2f.",floattype);

//double型

nslog(@"the value of integertype = %e.",doubletype);

//短整型

nslog(@"the value of integertype = %d.",shorttype);

//長整形

nslog(@"the value of integertype = %ld.",longlongtype);

//c語言字串

nslog(@"the value of integertype = %s.",cstring);

列印結果:

2016-10-09 17:07:01.375231 ocdemo[12845:1095736] 格式化輸出資料

2016-10-09 17:07:01.375249 ocdemo[12845:1095736] the value of integertype = 5.

2016-10-09 17:07:01.375302 ocdemo[12845:1095736] the value of integertype = 3.14.

2016-10-09 17:07:01.375319 ocdemo[12845:1095736] the value of integertype = 2.203300e+00.

2016-10-09 17:07:01.375329 ocdemo[12845:1095736] the value of integertype = 200.

2016-10-09 17:07:01.375337 ocdemo[12845:1095736] the value of integertype = 7758123456767.

2016-10-09 17:07:01.375362 ocdemo[12845:1095736] the value of integertype = this is a string!.

//基本資料型別封裝到nsnumber類中

nsnumber *num = [nsnumber numberwithint:88];

//nsnumber示例取出基本型別資料

nsinteger integer = [num intvalue];

nsinteger integernumber = 888;nsstring * string = [nsstring stringwithformat:@"%d",integernumber];

nslog(@"string is %@", string);integer = [string intvalue];nslog(@"integer is%d", integernumber);

Objective C語法之基本資料型別

格式化字串 物件 d,i 整數 u 無符整形 f 浮點 雙字 x,x 二進位制整數 o 八進位制整數 zu size t p 指標 e 浮點 雙字 科學計算 g 浮點 雙字 s c 字串 s pascal字串 c 字元 c unichar lld 64位長整數 long long llu 無符64位...

Objective C中的基本資料型別

main.m 01.基本資料型別 created by zhangqs008 on 14 2 13.import int main int argc,const char argv return 0 輸出結果 2014 02 13 21 19 33.633 01.基本資料型別 1463 303 01...

Objective c語言 基本資料型別封裝和拆包

import int main int argc,const char argv cgsize size cgrect rect nsrange包含了兩個成員,location 以及 length。location表示起始位置,以0開始 length表示長度 nsrange range cgpoin...