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: 
You can define a `static` variable inside a function, then it is only available in that function (and keeps its value between multiple calls):

```
int increment() {
  static int x = 0; // Initialize with 0
  x++;
  return x;
}

void main() {
  printf("%d\n", increment());
  printf("%d\n", increment());
  printf("%d\n", increment());

  // (unfortunately) x is not available here...
}

Returns:
1
2
3

```

Each time the `increment()` function is called, it will return a higher number.

It is not possible to use variables outside it scope. So you could either define a variable in the 'global scope' (as demonstrated by [Kerrek SB](https://stackoverflow.com/questions/7025934/how-to-declare-a-global-variable-which-is-present-in-only-one-function/7026011#7026011)) or a static variable in a function (or any other scope) (as demonstrated above). If any of these possibilities are not to applicable for your situation, I am afraid you should (drastically) modify the structure of you application...
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`