David RF
2/11/2011 11:30:00 AM
On 11 feb, 10:51, Mateusz_madi <madi.cz...@gmail.com> wrote:
> On 11 Lut, 10:17, David RF <davran...@gmail.com> wrote:
>
>
>
> > On 11 feb, 09:58, Mateusz_madi <madi.cz...@gmail.com> wrote:
>
> > > Hi i have 2 modules program:
>
> > > a.c
> > > ---------
> > > #include<stdio.h>
>
> > > int a=3;
>
> > > void drukuj(){
> > > printf("%d", a);
>
> > > }
>
> > > -----------
> > > b.c
> > > -----------
>
> > > #include<stdio.h>
>
> > > int a;
>
> > > int main()
> > > {
> > > a=8;
> > > drukuj();}
>
> > > ---------
>
> > > Why it prints 8 not 3.
>
> > Because a have global scope
>
> > Declare a as static in file b.c
> > static int a;- Ukryj cytowany tekst -
>
> > - Pokaz cytowany tekst -
>
> There is something i don't understand about global variables. I found
> in many pages that:
> "Global - All the modules in the project - The life of the program
> execution "
> buth if i declare global let's say g in one module and would like to
> increment it in second module it is impossible, so where is that
> global (All the modules in the project) scope?
Ok, I try to explain with my poor english
both a in a.c and b.c point to same location and have global scope, a
in b.c is redeclared, all variables declared without static duration
outside a function have global scope