变量定义与声明的区别(5)
时间:2026-01-23
时间:2026-01-23
变量定义与声明的区别
-----大部分内容来自博客小鱼研发手记的文章《变量的定义和声明的差别》
(/leven/archive/2005/06/16/44793.aspx) 今天读到林锐的书《高质量C++/C编程指南》,对其中的声明和定义内容颇有微辞。 声明(Declaration)用于说明每个标识符的含义,而并不必为每个标识符预存储空间。预留存储空间的声明称为定义(Definition)。声明的形式为:声明说明符 声明符声明符是由存储类说明符和类型说明符组成的。
1、变量的声明有两种情况: 一种是需要建立存储空间的。
例如:int a 在声明的时候就已建立了存储空间。
2、另一种是不必建立存储空间。
例如:extern int a 其中 变量a是在别的文件中定义的。
例一:
Declaration.
A construct which associates attributes to a variable name or function. No storage is reserved. For example:
extrn int a;
extrn char c;
variable declaration A structure decleration could look like:
Definition.
Variable definition is a declaration with storage allocation.
A construct which specifies the name,parameters and return type of a function. For example a function definition would be:
上一篇:股票投资分析