Query on the scope of local variables in C
Posted
by darkie15
on Stack Overflow
See other posts from Stack Overflow
or by darkie15
Published on 2010-06-14T13:59:08Z
Indexed on
2010/06/14
14:02 UTC
Read the original article
Hit count: 202
c
|variable-scope
All,
Consider the following code:
void func(void)
{
int a;
printf ("%d", a);
}
int main(int argc, char **argv)
{
int a = 3;
func();
printf("%d", a);
}
According to my understanding, the output should be:
<junk value><3>
Can anyone please confirm my understanding? My basic query is, does the compiler refer to the outer scope for a variable that has been declared but not defined?
Regards, darkie
© Stack Overflow or respective owner