On Aug 12, 8:17 pm, s0s...@gmail.com wrote:
> On Aug 12, 9:55 pm, mdh <m...@comcast.net> wrote:
>
> > On Aug 12, 7:51 pm, s0s...@gmail.com wrote:
>
> > > On Aug 12, 9:36 pm, mdh <m...@comcast.net> wrote:
>
> > > > If an array is defined , not as a static, but outside of a function,
> > > > is there any guarantee as to the contents of each element?
>
> > > A variable (of any kind, including an array) declared outside a
> > > function always has static storage duration, and declaring such a
> > > variable with the 'static' storage class makes it have internal
> > > linkage. So yes, an array declared outside a function is guaranteed
> > > have all its elements set to zero.
>
> > So,just to be sure, the only difference in using the actual word
> > 'static' in the declaration/definition is the scope of that variable?
>
> A declaration *inside* a function with the 'static' storage class
> makes the variable have static storage duration (i.e., it retains it's
> value from program startup until program termination).
>
> A declaration *outside* a function with the 'static' storage class,
> however, has a different meaning: it makes it have "internal
> linkage" (i.e., the variable/function is visible throughout file where
> it's declared, but not in other files), as opposed to "external
> linkage" (i.e., the variable/function is visible to all the files in
> the program), which is the default for variables/functions declared
> outside any function.
>
> The "scope" of a variable, which is what you mentioned, is something
> different from "linkage." A variable can have "file scope" (i.e., it's
> visible throughout the whole file where it's declared, and therefore
> to all functions in the file), or "block scope" (i.e., it's declared
> inside a function or inside a block inside the function, and therefore
> it's visible only inside that block).
>
> Sebastian
Thank you Sebastian