What do the terms mean in each of the above languages? Why do the languages differ (wherever they do, if at all they do) in this respect?
相关问题
- thread_local variables initialization
- Initializing variables, variable scope and import_
- How to initialize a 2D array of strings in java
- Are there advantages of declaring functions before
- variable length arrays in C and initializing it in
相关文章
- F# Object Initialization with a Constructor
- Is it guaranteed that defaulted constructor initia
- Scala variadic functions and Seq
- Initialization in polymorphism of variables
- Is Type name = name; ever useful in C++?
- How do I value-initialize a Type* pointer using Ty
- Why doesn't calling member function invoke the
- Initialization of static variables in C [duplicate
C/C++:
A declaration is a statement that says "here is the name of something and the type of thing that it is, but I'm not telling you anything more about it".
A definition is a statement that says "here is the name of something and what exactly it is". For functions, this would be the function body; for global variables, this would be the translation unit in which the variable resides.
An initialization is a definition where the variable is also given an initial value. Some languages automatically initialize all variables to some default value such as 0, false, or null. Some (like C/C++) don't in all cases: all global variables are default-initialized, but local variables on the stack and dynamically allocated variables on the heap are NOT default initialized - they have undefined contents, so you must explicitly initialize them. C++ also has default constructors, which is a whole nother can of worms.
Examples:
I'm not as familiar with the other languages you asked about, but I believe they don't make much of a distinction between declarations and definitions. C# and Java have default initialization for all objects - everything is initialized to 0, false, or null if you don't explicitly initialize it. Python is even more lax, since variables don't need to be declared before they're used. Since bindings are resolved at runtime, there's no real need for declarations of functions, either.