In c an static variable unlike auto(default) variable stays in memory and retains its value till program Runs.
whereas In c++ an static variable can be accesses from class resolution without even instantiating any object. Also any number of may be there , but there exists only single copy of static variable in c++ for all class.
for c consider example :
void staticvar()
{
int x=0;
static int y=0;
x++;
y++;
printf("%d %d "x,y);
}
void main()
{
staticvar();
staticvar();
}
output:
1,1
1,2// static retains its value.Auto (x) looses
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment