I tend to use the words define, declare and assign interchangeably but this seems to cause offense to some people. Is this justified? Should I only use the word declare for the first time I assign to a variable? Or is there more to it than that?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
A definition is where a value or function is described, i.e. the compiler or programmer is told precisely what it is, e.g.
A declaration tells the compiler, or programmer that the function or variable exists. e.g.
An assignment is when a variable has its value set, usually with the = operator. e.g.
Define and declare are similar but assign is very different.
Here I am declaring (or defining) a variable:
Here I am assigning a value to that variable:
Here I am doing both in one statement:
Note
Not all languages support declaration and assignment in one statement:
T-SQL
Some languages require that you assign a value to a variable upon declaration. This requirement allows the compiler or interpreter of the language to infer a type for the variable:
Python