Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
static in Introduction of Programming in C
1186 Views
C Storage class specifier: STATIC 
Static variables are generally retains its values even after the control is transferred to the calling function.
Program Hints 
a is static variable it is retains its value and initializing the value only once. b is auto variable it is initializing the value again and again so printing 1 only.
Program
#include
void print_value(void){
   static int a = 0;
   int b = 0;
   a = a + 1;
   b = b + 1;
   printf("%d = %d\n",a,b);
}
void main(){
   print_value();
   print_value();
   print_value();
}
Output 
1-1
2-1
3-1
Next Topics
Next lessons of current book.
Introduction of Programming in C
Introduction of Programming in C
Previous Topics
Previous lessons of current book.
Introduction of Programming in C
Introduction of Programming in C
Best Lessons of "Programming in C"
Top lessons which are viewed more times.
Structures and Unions of Programming in C
Input Output Functions of Programming in C
Structures and Unions of Programming in C
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details