#include <iostream>
int a;
void foo();
int main()
{
std::cout << "a = " << a << std::endl;
foo();
return 0;
}
void foo(){
int b;
std::cout << "b = " << b << std::endl;
}
Output:
a = 0
b = 32650
I have created a function named foo
that declares a int
variable and prints it. It prints some junk value because b
is not initialized at the time of declaration then how is a
getting initialized to 0
everytime?
Why is a
initialized to 0
while b
being initialized to some junk value?