0%

C-2

变量(Variables)和常量(constants)是一个程序中基本的操作对象。
对象的类型决定了值域和对应的操作。


约定:lower case for variable namesupper case for symbolic constant

At least the first 31 characters of an internal name are significant. For function names and external variables, the number may be less than 31, because external names may be used by assemblers and loaders over which the language has no control. For external names, the standard guarantees uniqueness only for 6 characters and a single case.
在早期 C 标准中,局部变量名至少前 31 个字符有意义;
而函数名和全局变量名因为依赖汇编器/链接器,可能更短,标准只保证前 6 个字符(不分大小写)有效,所以名字过长或大小写不同可能被当成同一个符号。
不同编译器有不同的实现。

数据类型和长度

C语言中的类型很少:char, int, float, double

除此之外还有一些 qualifiers 可以修饰这些类型
比如 short, long, signed, unsigned

1
2
3
short int sh;
long int counter;
// int 可以省略

shortlong 的目的是提供不同长度的整型数据,int一般是机器的 nature size
short 一般是 16 bits,int一般是 16 bits 或者 32 bits,取决于编译器

<limits.h> 和 <float.h> 中定义了关于类型大小的符号常量。

Q:写一个程序打印各个类型的取值范围