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.
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...