//
// 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;
}

输出结果:

2014-02-13 21:19:33.633 01.基本数据类型[1463:303] 01.基本数据类型长度

2014-02-13 21:19:33.634 01.基本数据类型[1463:303] The size of an int is: 4 bytes.

2014-02-13 21:19:33.635 01.基本数据类型[1463:303] The size of a short int is: 2 bytes.

2014-02-13 21:19:33.635 01.基本数据类型[1463:303] The size of a long int is: 8 bytes.

2014-02-13 21:19:33.635 01.基本数据类型[1463:303] The size of a char is: 1 bytes.

2014-02-13 21:19:33.636 01.基本数据类型[1463:303] The size of a float is: 4 bytes.

2014-02-13 21:19:33.636 01.基本数据类型[1463:303] The size of a double is: 8 bytes.

2014-02-13 21:19:33.636 01.基本数据类型[1463:303] The size of a bool is: 1 bytes.

2014-02-13 21:19:33.637 01.基本数据类型[1463:303] 02.格式化输出

2014-02-13 21:19:33.637 01.基本数据类型[1463:303] The value of integerType = 5

2014-02-13 21:19:33.637 01.基本数据类型[1463:303] The value of floatType = 3.14

2014-02-13 21:19:33.638 01.基本数据类型[1463:303] The value of doubleType = 2.203300e+00

2014-02-13 21:19:33.639 01.基本数据类型[1463:303] The value of shortType = 200

2014-02-13 21:19:33.639 01.基本数据类型[1463:303] The value of longlongType = 7758123456767

2014-02-13 21:19:33.640 01.基本数据类型[1463:303] The value of cstring = this is a string!

2014-02-13 21:19:33.640 01.基本数据类型[1463:303] 03.NSStringNSInteger的相互转换

2014-02-13 21:19:33.640 01.基本数据类型[1463:303] string is 888

2014-02-13 21:19:33.641 01.基本数据类型[1463:303] integer is 888

Program ended with exit code: 0

附:格式化输出符号:

%@          对象

%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位长整数

%Lf         64位双字

%e          实数,用科学计数法计

Objective-C中的基本数据类型的更多相关文章

  1. PowerShell中的基础数据类型

    PowerShell是一个面向对象的语言,在申明变量的时候不强制要求申明数据类型,使用$开头来申明变量即可. 基本数据类型 PowerShell本身是基于.Net开发出来的,所以在.Net中的基本数据 ...

  2. MySql中的字符数据类型

    MySql中的varchar类型 1.varchar类型的变化 MySQL数据库的varchar类型在4.1以下的版本中的最大长度限制为255,其数据范围可以是0~255或1~255根据不同版本数据库 ...

  3. [.net 面向对象编程基础] (3) 基础中的基础——数据类型

    [.net 面向对象编程基础] (3) 基础中的基础——数据类型 关于数据类型,这是基础中的基础. 基础..基础..基础.基本功必须要扎实. 首先,从使用电脑开始,再到编程,电脑要存储数据,就要按类型 ...

  4. Mssql中一些常用数据类型的说明和区别

    Mssql中一些常用数据类型的说明和区别 1.bigint 占用8个字节的存储空间,取值范围在-2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,37 ...

  5. JAVA中分为基本数据类型及引用数据类型

    一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节,取值范围-128~127,默认值0 short:短整型,在内存中占16位,即2个字节,取值范围-32768 ...

  6. SQL Server中的Image数据类型的操作

    原文:SQL Server中的Image数据类型的操作 准备工作,在库Im_Test中建立一张表Im_Info,此表中有两个字段,分别为Pr_Id (INT),Pr_Info (IMAGE),用来存储 ...

  7. 二、java中的基本数据类型

    总结: 1.java中的基本数据类型有byte.short.int.long;float.double;char;boolean. 2.基本数据类型与1相对应分别占1.2.4.8;4.8;2;1.(单 ...

  8. 理解Objective C 中id

    什么是id,与void *的区别 id在Objective C中是一个类型,一个complier所认可的Objective C类型,跟void *是不一样的,比如一个 id userName, 和vo ...

  9. 浅谈Objective—C中的面向对象特性

    Objective-C世界中的面向对象程序设计 面向对象称程序设计可能是现在最常用的程序设计模式.如何开发实际的程序是存在两个派系的-- 面向对象语言--在过去的几十年中,很多的面向对象语言被发明出来 ...

  10. SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型

    原文:SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 R2调测 ...

随机推荐

  1. arcengine帮助http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/what_s_new_for_developers_at_10_/0001000002zp000000/

    http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/what_s_new_for_develope ...

  2. Android之旅十四 android中的xml文件解析

    在我们做有关android项目的时候,肯定会涉及到对xml文件的解析操作.以下给大家介绍一下xml文件的解析.包括DOM.SAX.Pull以及曾经我们用到的DOM4J和JDOM: 要解析的XML文件: ...

  3. pytest文档9-参数化parametrize

    前言 pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1.这里是一个实现检查一定的输入和期望输出测试功能的典型例子 # content of ...

  4. ContentProvider的那些小事(纯结论)

    一.ContentProvider背景 Android系统是基于Linux系统内核来进行开发的,在Linux中,文件具有一系列的属性,其中最重要的莫过于文件权限了.关于文件权限,其实就是文件的读写,执 ...

  5. Informatica 常用组件Source Qualifier之二 默认查询

    2 默认查询 对于关系源,PowerCenter Server 将在运行会话时为每个源限定符转换生成查询.对于每个在映射中使用的源列,默认查询均为 SELECT 语句.也就是说,PowerCenter ...

  6. Power Desginer系列01【转摘】

    近期在做一个业务系统的分析和数据模型设计,工作这几年也做过好几个项目的数据库模型的设计,期间也算是积累了一定的经验吧,这次有机会就写写我的数据库模型设计过程与方法. 在 数据库设计中,设计的目标就是要 ...

  7. jquery的$.each()

    each()方法能使DOM循环结构简洁,不容易出错.each()函数封装了十分强大的遍历功能,使用也很方便,它可以遍历一维数组.多维数组.DOM, JSON 等等在javaScript开发过程中使用$ ...

  8. JSP学习笔记(四):文件上传

    JSP 可以与 HTML form 标签一起使用,来允许用户上传文件到服务器.上传的文件可以是文本文件或图像文件或任何文档.我们使用 Servlet 来处理文件上传,使用到的文件有: upload.j ...

  9. PyDev:warning: Debugger speedups using cython not foun

    在eclipse下调试代码开始时总提示一个警告: warning: Debugger speedups using cython not found. Run '"C:\Python36\p ...

  10. 转: SVN和Git的一些用法总结

    转:http://www.codelast.com/?p=5719 转载请注明出处:http://www.codelast.com/ 以下都是比较基础的操作,高手们请绕道,不必浪费时间来看了. (A) ...