Published on: 12th Nov 2010 | Last Updated on: 24th Nov 2011
Static Storage Class :
- Keyword : static
- Storage Location : Main memory
- Initial Value : Zero and can be initialize once only.
- Life : depends on function calls and the whole application or program.
- Scope : Local to the block.
Syntax :
static [data_type] [variable_name];
Example :
static int a;
There are two types of static variables as :
a) Local Static Variable
b) Global Static Variable
Static storage class can be used only if we want the value of a variable to persist between different function calls.
Program :
/* Program to demonstrate static storage class.
Creation Date : 10 Nov 2010 00:14:22 AM
Author : www.technoexam.com [Technowell, Sangli] */
#include <stdio.h> #include <conio.h> void main() { int i; void incre(void); clrscr(); for (i=0; i<3; i++) incre(); getch(); } void incre(void) { int avar=1; static int svar=1; avar++; svar++; printf("\n\n Automatic variable value : %d",avar); printf("\t Static variable value : %d",svar); }
Output :
Automatic variable value : 2 Static variable value : 2 Automatic variable value : 2 Static variable value : 3 Automatic variable value : 2 Static variable value : 4_
Link this post on your Blog/Website :

