Undefined values: Difference between revisions

C++ entry
m (→‎{{header|6502 Assembly}}: Rephrased for clarity)
(C++ entry)
Line 168:
}</lang>
So it's a little compiler magic but in the end works just as one would expect.
 
=={{header|C++}}==
 
In C++, a variable that has not been initialized has an undefined value which cannot be tested or used in any
way. Attempting to use an undefined value results in undefined behavior. In the code below, anything could
happen. It may print '42', 'not 42', both, or nothing at all. The unexpected behavior happens because since
the behavior is undefined, the compiler can do whatever it wants. Most compilers will give a warning.
 
<lang cpp>#include <iostream>
 
int main()
{
int undefined;
if (undefined == 42)
{
std::cout << "42";
}
if (undefined != 42)
{
std::cout << "not 42";
}
}</lang>
{{out}}
<pre>
? ? ?
</pre>
 
=={{header|Common Lisp}}==
125

edits