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

What is the method to save data in stack data structure type?

600


How can you increase the size of a statically allocated array?

608


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

635


why we wont use '&' sing in aceesing the string using scanf

1777


Differentiate between static and dynamic modeling.

613






how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12

648


What is the use of static variable in c?

593


How can I get random integers in a certain range?

609


What is difference between structure and union?

593


How is pointer initialized in c?

581


What is string concatenation in c?

565


Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.

1759


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1128


What is the mean of function?

644


What is array of pointers to string?

564