top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What would be the impact if we declare static variable in header file?

+3 votes
466 views
What would be the impact if we declare static variable in header file?
posted Oct 30, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

This static variable will the global static variable to that file which has include the header file which contains this
static variable.

For example:
Assume you have "test.h" header file where you have declare one static variable.
And another file "test.c" which included this "test.h" can be able to access the static variable( this static variable is only available to this file only i,e "test.c".

If some other .c file which is dependent on "test.c" try to use "exter key word" to use this static variable, it won't be possible because of the "static key word"

So this variable only is available for .c file which included that heard file which contains the static variable.

answer Oct 30, 2014 by Arshad Khan
Similar Questions
+5 votes

You can find three principal uses for the static. This is a good way how to start your answer to this question. Let’s look at the three principal uses:

  1. Firstly, when you declare inside of a function: This retains the value between function calls

  2. Secondly, when it is declared for the function name: By default function is extern..therefore it will be visible out of different files if the function declaration is set as static..it will be invisible for outer files

  3. And lastly, static for global parameters: By default you can use global variables from outside files When it’s static global..this variable will be limited to within the file.

is this right ?

+3 votes

As per my understanding uninitialized static variable is stored in BSS and initialized static variable is stored in DS, then what about the variable which is initialized with 0 ? where it will be stored BSS/DS?

...