This code snippet was taken from an online C Programming Quiz.
Please help me understand this code. Apparently it prints a garbage value. Here we have a local variable var, which hides the scope of the global variable var. I assumed that the local variable var is initialized with the value of the global variable var, the rvalue of the global var is copied into the local var. I understand that from that point on, the name var in the code now refers to the local var. So printing the local var should also print 5. But this is not the case. The program prints a garbage value. This means that the local var was uninitialized or some kind of error happened during initialization of the local var. What is going on here? Is this an issue of undefined behavior?
#include <stdio.h>
int var = 5;
int main() {
int var = var;
printf("%d", var);
}