0

Consider this code:

main()
{
void postinc();
postinc();
postinc();
postinc();
}
void postinc()
{
static int count=1;
printf("%d", count);
count++;
}

What will be the output?
Make me clear of this static concept.........
What happens to the variable count?
I know that it actually retains its value between funcion calls. But when it is called again and again when the control is passed to the function postinc will the stmt "static int count =1" change the previous value contained by count to 1? or will it still hold the value incremented previously. If it is so, what's the reason behind it?
Please reply me soon..................

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Adak
0

Also make me clear about other storage classes, if possible with examples...........

0

static variables are initialized just once, on the first call to the function.

There was a need for a static variable that would be encapsulated (could be used) by a certain function, and no others.

If you have a particular question about your program's storage classes, post up the code, and ask away.

It doesn't make sense to make a rather long tutorial about a general topic in a forum - it just gets moved off into the archives far too quickly, and then gone.

There are a number of good tutorials available on the net, some are even video's about C, from major colleges and universities. Why not Google them up and view a few?

Edited by Adak: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.