Static keyword


It is not a very complicated concept , if we use static with global variable then it restricts the scope of that variable to the program in which the variable is declared only same with function also

Static functions are only visible to the source code containing the function only , but if we declare a local variable static that means the lifetime of that variable will be from the first function call to the ending of the program otherwise local variable dies as soon as the function in which they are declared is over

static int x = 20; // global variable

static hello() //static function
{
static int y = 0; //static local variable
}
main()
{
hello();
getch();
}

No comments:

Post a Comment