Static variable

Hi,


static int a;
main()
{
printf("What is the use of global static variable");
}

Any one can tell me what is the real use of using static variable as global...?

Thanks

Comments

  • : Hi,
    :
    :
    : static int a;
    : main()
    : {
    : printf("What is the use of global static variable");
    : }
    :
    : Any one can tell me what is the real use of using static variable as
    : global...?
    :
    : Thanks
    :
    A static global variable's scope is only the file where the variable is declared. So to restrict the scope of a global variable, this approach is used.
    [hr][purple]~Donotalo()[/purple]
  • This means that if someone tries to type "extern int a;" in another file, they will get a linker error, just because of the static keyword. So the purpose is to 1) prevent against bad programming practice / spaghetti code, and 2) make sure nobody uses the variable elsewhere in the program by mistake.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories