0
void init1()
{
 static int yrs = 1;
 cout << "The value of yrs is " << yrs << endl;
 yrs = yrs + 2;
 return;
}
void init2()
{
 static int yrs;
 yrs = 1;
 cout << "The value of yrs is " << yrs << endl;
 yrs = yrs + 2;
 return;
}
2
Contributors
4
Replies
18
Views
3 Years
Discussion Span
Last Post by daniela.valkanova
0

Sounds like homework.

What do you think the implications of splitting up line 3 is? What does static do?

0

Good! In the first example, the value isn't set. It's initialized. In the second example, the value is set on each call.

This question has already been answered. 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.