What will be the output of the under given program?
#include<iosteam.h>
void main()
{
int k;
cout<<”k=”<<k;
}
-
An error
-
Unpredictable
-
567
-
0
B
Correct answer
Explanation
The variable k is declared but never initialized. In C++, reading an uninitialized local variable results in undefined behavior - the output will be whatever garbage value happens to be in that memory location. This is unpredictable and can vary between runs. Option B (Unpredictable) correctly identifies this behavior. Note that the header has a typo: 'iosteam.h' should be 'iostream.h', but the conceptual question about uninitialized variables is still valid.