Variable a is declared in two separate functions, but only initialized in one of them. The main function calls the function that declares and initializes a, then it calls the second function which redeclares that variable without initializing it. It prints 42, even though a is initialized in a different function scope whose data should have been destroyed after the function's completion. Why is this happening?
#include <stdio.h>
void foo() {
int a = 42;
}
void bar() {
int a;
printf("%d",a);
}
main() {
foo();
bar();
}