Question: I need to declare a global variable which is only available if a certain function is called.
If that function is not called than that variable should not be available.

```
 void function()
 {
   // if this function is called then declare int a=10; 
   // as global so other function can use this 
 }

```

How can I do such a thing in c?

Answer: 
C is not a dynamic language - all declared variables exist (subject to scoping rules) at all times.

You cannot test whether a variable has been *declared*, that's the compilers job, and it'll give you an error if you try to use one that's not in scope.

*Global* variables have space allocated for them (in the "data" segment) automatically when the program is first loaded.

Hence you can only test whether the variable has changed from its original assigned value.
There is no way You can restrict scope of global variable to one function in file ,It is available to all the functions in a file ,However You can restrict the scope of global variable to a file only, by using static keyword with global variable name.

```
   file1.c //1st file                     file2.h //2nd file

   #include<file2.h>                     
   main()                                static int a;
   {
   fun();                                 fun()
   }                                      {
                                           printf("%d",a);
                                          }

```

In the example you do have two files file1.c and file2.h ,Now variable a is available to function fun() only in 1st file.