Tag: What is static variable

What is static variable ?

February 22, 2010 | Filed Under C | Comments Off

Basically it has three core feature.

1. It retains the value between function calls.
2.By default function is extern..so it will be visible from other files if the function declaration is as static..it is invisible for the outer files

3. By default we can use the global variables from outside files If it is static global..that variable is limited to with in the file.

#include <stdio.h>

int variable = 10;

main(){

int i = 0;
void useStatic();
style="color: #7f0055;"> #000000;">useStatic();
printf("after 1st call \n");
useStatic();
printf("
after 2nd  call \n");
useStatic();
printf("
after IIIrd call \n");

}
void useStatic()
{
static int j = 0;
int k = 10;
printf("value of j %d k %d",j,k);
j=j+10;
}

value of j 0 k 10 After 1st call
      value of j 10 k 10 After IInd call
      value of j 20 k 10 After IIUrd call
Article written by admin

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker