C语言复习

C语言的数据结构

基本类型:整型,字符型,实型(浮点型,包括单精度型和双精度型),枚举类型

构造类型:数组类型,结构体类型,共用体类型

指针类型

空类型


常量如定义:

#define PRICE 30

这种用一个标识符代表一个常量的,称为符号常量,即标识符形式的常量。

通常,符号常量名用大写,变量名用小写,以示区别。

变量

变量名和变量值。在程序中重变量中取值,实际上是通过变量名找到相应的内存地址,从其存储单元中读取数据。

C语言规定标识符(identifier)只能由字母、数字和下划线三种字符来组成,而且第一个字符必须为字母或下划线。

数值是以补码(complement)形式表示的,一个正数的补码和其原码相同,而一个负数则不相同了。方法是:将这个数的绝对值的二进制形式,按位取反再加1。

比如-10,10的二进制是1010,取反位0101,再加1得0110。

10的原码:0000 0000 0000 1010

取反: 1111 1111 1111 0101

加1: 1111 1111 1111 0110

所以说,在整数的16位中,最左面的一位是表示符号的,0为正,1为负。

整型变量的分类

在int前可加修饰符 short, long

一个int型变量的值的范围:-32768~32767

如果将变量定义为unsigned,即无符号数,则为0~65535

而修饰符signed可以不写,默认就是有符号数的。

这样就有6种整型变量:

类型 最小取值范围

[signed] int -32768~32767

unsigned int 0~65535

[signed] short [int] -32768~32767

unsigned short [int] 0~65535

long [int] -2147483648~2147483647

unsigned long [int] 0~4294967295

[]内的部分可以省略不写。上面是ANSI标准定义的整数类型和有关数据,最小取值范围是指不能低于此值,但可以高于此值。

C标准没有规定这些数据所占的字节数,只是要求long型数据长度不低于int型,short型不长于int型。

一个整常量后面加字母u,认为是unsigned int 型,如12345u,

若加字母l或L,则认为是long int 常量,例如123l, 432L, 这些常常用于函数调用中。





Popularity: 12% [?]




50% OFF Coupon: 50OFF

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2010 时光漫步. All rights reserved.
Powered by WordPress.org, Custom Theme and ComFi.com Calling Card Company.