//Program: Static and automatic variables
#include <iostream>
usingnamespace std;
void test();
int main()
{
int count;
for (count = 1; count <= 5; count++)
test();
system ("Pause");
return 0;
}
void test()
{
staticint x = 0;
int y = 10;
x = x + 2;
y = y + 1;
cout << "Inside test x = " << x << " and y = "
<< y << endl;
} Put the code you need help with here.
Output
1 2 3 4 5
Inside test x =2 and y =11
Inside test x =4 and y =11
Inside test x =6 and y =11
Inside test x =8 and y =11
Inside test x =10 and y =11
Ok thanks for that link fabtasticwill.
When we declared x as the static variable the value of x will changed but when we just declared y is int it will not changed anything.