what are the static variables

Answer Posted / prakash.m

static variables are those which retains the outcoming
value after 'n' iterations(initialized once)

(see below)
#include <stdio.h>

int g = 10;

main(){

int i =0;
void f1();
f1();
printf(" after first call \n");
f1();
printf("after second call \n");
f1();
printf("after third call \n");

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


the output will be:

value of k 0 j 10 after first call
value of k 10 j 10after second call
value of k 20 j 10after third call

hope this will help u....

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In a header file whether functions are declared or defined?

872


What is difference between union All statement and Union?

865


What are all different types of pointers in c?

763


Is javascript written in c?

785


What is the c language function prototype?

847


What are the features of c language?

816


Explain the properties of union.

813


what is bit rate & baud rate? plz give wave forms

1719


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1148


Suggesting that there can be 62 seconds in a minute?

790


What are the storage classes in C?

811


What is the advantage of a random access file?

849


Explain how do I determine whether a character is numeric, alphabetic, and so on?

871


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

964


What is substring in c?

856