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.
It is recommended to avoid use of global variables as far as possible.
In your particular case what you can do is simply:

```
function(int* toModify)
{
    *toModify = 10;
    // do sth
}

```

Now your other functions can use the modified value.

However, if you are keen on using a global variable, you have to use two global vars,

```
int gIsFuncCalled = 0;
int gToModify = 0;

void function() 
{ 
    gIsFuncCalled = 1;
    gToModify = 10;
}

```

Now you can use `gToModify` conditionally using `gIsFuncCalled`