variables in c

  • From: Daniel Dalton <daniel.dalton47@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sat, 22 Sep 2007 20:32:15 +1000

Hi,

If I write:

#include <stdio.h>
int x =6, y =78;
void my_function(void);
int main ()
{
printf("\nx =%d and y =%d", x, y);
my_function ();
printf("Left my_function\n");
printf("\nx now =%d and y now =%d", x, y);
}

void my_function (void)
{
int x =124, y =245;
printf("\nIn my_function\n");
printf("x =%d y =%d\n", x, y);
}

So are both x and y variables local?
        
The second line of the program(int x, y;) isn't in a function. So how does the compiler know what function they are for? Are they global variables? If they are then how can you have a local variable called the same thing as a global variable?
Thanks,

-- Daniel Dalton

http://members.iinet.net.au/~ddalton/
daniel.dalton47@xxxxxxxxx
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: