//
// main.m
// 01.基本数据类型
//
// Created by zhangqs008 on 14-2-13.
// Copyright (c) 2014年 zhangqs008. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
//01.基本数据类型长度
NSLog(@"01.基本数据类型长度");
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));
//02.格式化输出
NSLog(@"02.格式化输出");
int integerType = 5;//整型
float floatType = 3.1415; //浮点型
double doubleType = 2.2033;//双浮点型
short int shortType = 200;//短整型
long long int longlongType = 7758123456767L;//长整型
char * cstring = "this is a string!";//c语言字符串
//整型
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);
//03.NSString与NSInteger的相互转换
NSLog(@"03.NSString与NSInteger的相互转换");
NSInteger integerNumber = 888;
NSString *string = [NSString stringWithFormat:@"%ld",(long)integerNumber];
NSLog(@"string is %@", string);
NSInteger integer = [string intValue];
NSLog(@"integer is %ld", (long)integer);
//04.int,NSInteger,NSUInteger,NSNumber
//1.当需要使用int类型的变量的时候,可以像写C的程序一样,用int,也可以用NSInteger,但更推荐使用NSInteger,因为这样就不用考虑设备是32位的还是64位的。
//2.NSUInteger是无符号的,即没有负数,NSInteger是有符号的。
//3.NSInteger是基础类型,但是NSNumber是一个类。如果想要在NSMutableArray里存储一个数值,直接用NSInteger是不行的,必须转换为数字对象;
}
return 0;
}
转载于:https://my.oschina.net/zhangqs008/blog/200154