What is a static variable?

Trainee Asked on August 15, 2019 in C++ Language.
Add Comment
1 Answer(s)

A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice.

void f() 
{ 
   static int i; 
   
   ++i; 
   printf(“%d “,i); 
}

If a global variable is static then its visibility is limited to the same source code.

Supporter Answered on August 15, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.