In computer science, initialization means to give an initial value to a variable in a program.

In computer programming, you usually work with variables. Depending on the programming language and how your program works, your program may end up using (referencing) a variable before any value has been assigned to it; in this case, the value in the variable may be random or garbage, and doing further operations with this value can lead to problems.

A major problem is the use of uninitialized pointers. A pointer with a random value will most likely point into an area of memory the program is not allowed to access, and dereferencing this pointer will usually cause the program to abort.

All this can be avoided by assigning a "good" value, i.e. any known and legal one, to the variable before it is first used, in other words, initialization.

Some computer languages, such as Java, have special provisions for this problem. Code sequences where variables are not or may not be initialized are flagged for the programmer's attention, and in Java such occurrences even constitute an error, meaning that the compilation will fail until proper care is given to initializing the variable(s) in question.

Log in or register to write something here or to contact authors.