C语言中各种数据类型长度.doc_第1页
C语言中各种数据类型长度.doc_第2页
C语言中各种数据类型长度.doc_第3页
C语言中各种数据类型长度.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

下面是我关于C语言中各种数据类型长度的总结:(参考The C Programming Language)1. c语言中的整数类型有char, short, int, long等几种, 下面是C语言对每种数据类型长度的规定:(a). short和long类型的长度不相同(b). int类型通常同具体机器的物理字长相同(c). short通常是16bits, int通常是16bits or 32bits每种编译器可以根据硬件的不同自由确定, 但是short和int必须最少是16bits, 而long类型必须最少是32bits, 并且short必须比int和long类型要短。2. sizeof() 运算符返回的是一种数据类型中所包含的字节数(bytes), AnsiC规定sizeof(char)必须返回1,当sizeof作用于数组时, 返回的是数组中所有成员所占的字节数(注意并不是数组中成员的个数), 当sizeof()作用于结构体和公用体时,返回的不仅仅是数据成员总的字节数, 还包括编译器为了实现字节对其而填充的那些字节。以前写程序也隐隐约约的懂得这些规则,但是一直以为char类型必须是8bits的,但是最近做了一个嵌入式DSP项目,编译器手册上明明写着char类型就是16bits的,无奈翻出The C Programming Language一查才发现ANSI C对于char类型的长度并没有作硬性规定。以前写程序不太注意数据类型的可移植性, 这次项目中用到的以前的代码都要重新检查数据类型长度的问题。C Data types.Variable definitionC has a concept of data types which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location. So what data types are available? int float double char void enum Please note that there is not a boolean data type. C does not have the traditional view about logical comparison, but thats another story. Recent C+ compilers do have a boolean datatype. int - data typeint is used to define integer numbers. int Count; Count = 5; float - data typefloat is used to define floating point numbers. float Miles; Miles = 5.6; double - data typedouble is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes. double Atoms; Atoms = 2500000; char - data typechar defines characters. char Letter; Letter = x; ModifiersThe three data types above have the following modifiers. short long signed unsigned The modifiers define the amount of storage allocated to the variable. The amount of storage allocated is not cast in stone. ANSI has the following rules: short int = int = long int float = double +32,767 (32kb) unsigned short int 2 16 0 - +65,535 (64Kb) unsigned int 4 32 0 - +4,294,967,295 ( 4Gb) int 4 32 -2,147,483,648 - +2,147,483,647 ( 2Gb) long int 4 32 -2,147,483,648 - +2,147,483,647 ( 2Gb) signed char 1 8 -128 - +127 unsigned char 1 8 0 - +255 float 4 32 double 8 64 long double 12 96These figures only apply to todays generation of PCs. Mainframes and midrange machines could use different figures, but would still

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论