iOS 数据类型

OC:基本数据类型

字数450 阅读881 评论2 喜欢5
基本类型

类型限定修饰词

除了上图中基本类型之外,还有一些类型限定修饰词

  • short短型,修饰int、double;
  • long长型,修饰int、double;
  • signed有符号型,修饰int、char;
  • unsigned 无符号型,修饰int、char;

1.这些限定词经常用来限定int型,在限定int类型时int可以省略;
2.short和long会改变int型的长度,在不同编译器长度不相同,但是一般short长度不大于int,int长度不大于long;
3.signed和unsigned不会改变类型长度,仅表示最高位是否为符号位,其中unsigned表示大于等于0的正数;

取值范围

为了以后开发中能够方便查找,并正确的使用数据类型,下面是部分数据类型的取值范围:

  • int:-2147483648~2147483647
  • unsigned int:0~4294967295
  • short:-32768~32767
  • unsigned short:0~65535
  • long: -2147483648~2147483647
  • unsigned long:0~4294967295

存储空间

下面列出的是常用数据类型占用的存储空间

数据类型16位编译器32位编译器64位编译器
char 1byte 1byte 1byte
int 2byte 4byte 4byte
float 4byte 4byte 4byte
double 8byte 8byte 8byte
short int 2byte 2byte 2byte
unsigned int 2byte 4byte 4byte
long 4byte 4byte 8byte
unsigned long 4byte 4byte 8byte
long long 8byte 8byte 8byte
 
原文地址:https://www.cnblogs.com/xsyl/p/6055339.html