c语言数据类型

发布时间:2019-08-06 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了c语言数据类型脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

参考文章

说明符 + 限定符

数据类型一览表

算数类型(arIThmetic tyPE

字符类型

signed char     有符号字符
unsigned char   无符号字符
char            字符(可以是 signed charunsigned char,由实现定义)

// 除此之外,还定义了字符(c11):

1. wchar_t
2. char16_t
3. char32_t

整数类型

1. 短整形

short
signed short
short int
signed short int

// 等价于
short int

2. 无符号短整形

unsigned short
unsigned short int

// 等价于
unsigned short int

3. 整形

signed
int
signed int

// 等价于
int

4. 无符号整形

unsigned
unsigned int

// 等价于
unsigned int

5. 长整型

long
long int
signed long
signed long int

// 等价于
long int

6. 无符号长整型

unsigned long
unsigned long int

// 等价于
unsigned long int

7. long long int(c99,不懂该怎么称呼了...)

long long
long long int
signed long long
signed long long int

// 等价于
long long int

8. unsigned long long int(c99)

unsigned long long
unsigned long long int

// 等价于
unsigned long long int

数据模型

每种实现对数据类型的大小选择统称为 数据模型,以下四种是大家普遍接受的数据模型:

32 System

1. LP32 2/4/4,(int 16bit,long & pointer 32bit)
    1. 仅出现在 win16 API 中
2. LP32 4/4/4,(intlong,pointer 32bit)
    1. win32 API
    2. 类 unix 系统(linux or mac)

64 System

3. LP64 4/4/8,(int & long 32Big,pointer 64 bit)
4. LP64 4/8/8,(int 32 bit,long & pointer 64 bit)

其他模型非常罕见(几乎可以不用理会,实际就是无需理会)!举一个例子,数据模型 LP64 8/8/8(int & long & pointer 64 bit),这种数据模型只出现在早期的 unix 机器上

浮点类型

1. float    单精度浮点型    32bit(4byte)
2. double   双精度浮点型    64bit(8byte)
3. long double 扩展精密浮点型(需要机器支持) >=64 bit

如果使用了 complex.h,表示需要用到复杂的浮点数

以下写法都是有效的:

float _complex          float complex
double _complex         double complex
long double _complex    long double complex

float _imaginary        float imaginary
double _imaginary       double imaginary
long double _imaginary  long double imaginary

原子类型(atomic type),限定符

支持以下三种写法:

// p 是指向原子 const int 的指针
_Atomic const int * p1;
// 同上
const atomic_int * p2;
// 同上
const Atomic(int) * p3;

原子类型的对象是唯一不受数据竞争的对象,也就是说,它们可以由两个线程并发地修改,或者由另一个线程修改。

拥有以下四个相关属性:

1. 写入一致性(write-write-coherence)
2. 读取一致性(read-read-coherence)
3. 读写一致性(read-write-coherence)
4. 写读一致性(write-read-coherence)

具体解释参考官方文档:atomic type

目前的 Visual studio 中不支持该类型

由 typedef 引入的说明符

// 声明 int_t 是 int 的别名
typedef int int_t

// 进阶
// char_t 是 char 的别名
// chart_p 是 char* 的别名
// fp 是 char(*)(void) 的别名
typedef char char_t, *char_p, (*fp)(void)

修饰符

const

// 常量不可改动
const int a = 10;

volatile

// 提醒计算机:
// a 变量可能会实时更新,不能缓存
// 这个一般多用在多线程场景下
volatile int a = 10;

restrict

restrict 详解

特殊的常量

INFINITY    无穷
NaN         非数字

数值范围

如果需要准确的了解到数值的范围,请参阅(页面底部):各种类型对应的数值范围

脚本宝典总结

以上是脚本宝典为你收集整理的c语言数据类型全部内容,希望文章能够帮你解决c语言数据类型所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。