Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Uninitialized variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Use in languages== Uninitialized variables are a particular problem in languages such as assembly language, C, and [[C++]], which were designed for [[systems programming]]. The development of these languages involved a design philosophy in which conflicts between performance and safety were generally resolved in favor of performance. The programmer was given the burden of being aware of dangerous issues such as uninitialized variables. In other languages, variables are often initialized to known values when created. Examples include: * [[VHDL]] initializes all standard variables into special 'U' value. It is used in simulation, for debugging, to let the user to know when the [[don't care]] initial values, through the [[multi-valued logic]], affect the output. * [[Java (programming language)|Java]] does not have uninitialized variables. Fields of classes and objects that do not have an explicit initializer and elements of arrays are automatically initialized with the default value for their type (false for boolean, 0 for all numerical types, null for all reference types).<ref name="Java"/> Local variables in Java must be definitely assigned to before they are accessed, or it is a compile error. * [[Python (programming language)|Python]] initializes local variables to <code>NULL</code> (distinct from <code>None</code>) and raises an <code>UnboundLocalError</code> when such a variable is accessed before being (re)initialized to a valid value. * [[D (programming language)|D]] initializes all variables unless explicitly specified by the programmer not to. Even in languages where uninitialized variables are allowed, many [[compiler]]s will attempt to identify the use of uninitialized variables and report them as [[compile-time]] [[compilation error|error]]s. Some languages assist this task by offering constructs to handle the initializedness of variables; for example, [[C Sharp (programming language)|C#]] has a special flavour of call-by-reference parameters to subroutines (specified as <code>out</code> instead of the usual <code>ref</code>), asserting that the variable is allowed to be uninitialized on entry but will be initialized afterwards.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)