- Local Variables
- Formal Parameters
- Static Variables
- Global Variables
- Input Variables
- Extern Variables
- Initialization of Variables
- Visibility Scope and Lifetime of Variables
- Creating and Deleting Objects
Initialization of Variables
Any variable can be initialized during definition. If a variable is not initialized explicitly, the value stored in this variable can be any. Implicit initialization is not used.
Global and static variables can be initialized only by a constant of the corresponding type or a constant expression. Local variables can be initialized by any expression, not just a constant.
Initialization of global and static variables is performed only once. Initialization of local variables is made every time you call the corresponding functions.
Examples:
int n = 1;
|
List of values of the array elements must be enclosed in curly brackets. Missed initializing sequences are considered equal to 0.
If the size of the initialized array is not specified, it is determined by a compiler, based on the size of the initialization sequence.
Examples:
struct str3
|
For structure type variable partial initialization is allowed, as well as for static arrays (with an implicitly set size). You can initialize one or more first elements of a structure or array, the other elements will be initialized with zeroes in this case.
See also
Data Types, Encapsulation and Extensibility of Types, Visibility Scope and Lifetime of Variables, Creating and Deleting Objects