Mega Code Archive

 
Categories / C / Code Snippets
 

Define static variable inside function

#include <stdio.h> int g = 10; void f(); main() { int i =0; f(); printf(" after first call \n"); f(); printf("after second call \n"); f(); printf("after third call \n"); } void f() { static int y=0; int x = 10; printf("y= %d x= %d",y,x); y = y + 10; }