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: 
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.
declare it global as static and dont initialize it.
as soon as the function is called initialize it inside the function

i.e.

```
static int a;

void main()
{
  // Some code here
}

void function()
{
  a=10; 
  // Some code here as well

}

```