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 doesn't work like that - a global variable is allocated at load time and exists for the entire duration of the program, independent of the runtime behaviour. If you really must know whether the variable has been "set", you could include a separate flag:

```
int global_a;
int global_a_has_been_set = 0;

void f()
{
  global_a = 10;
  global_a_has_been_set = 1;
}

void elsewhere()
{
  if (global_a_has_been_set != 0) { /* ... */ }
}

```

If you know that your variable can only be non-negative, then you could alternatively use a special sentinel value like `-1` to indicate that the variable hasn't been "set" yet.

Most likely though is that you should rework your design so that you already know by other means whether or not you need the variable.
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`