Assignment
From Coderwiki
More actions
Variable declaration and variable assignment are two separate terms but are often confused.
What is assignment?
edit edit sourceAssignment is when we set the value of a variable.
In most statically-typed languages, we must first declare (create) the variable before we can give it a value. In some languages like Python, however, we can initialize any variable without needing to first declare it.
How does it differ from initialization?
edit edit sourceInitialization is also the process of giving a variable a value. So what's the difference?
Assignment is whenever we change the value of any variable, while initialization is only when it is first given a value.
This means that initialization is a type of assignment
Example: declaration and initialization in C
edit edit sourceint a; // declaration: we create the 'a' variable
a = 72; // initialization: we give 'a' a value
char b = 'b'; // declaration and initialization