// Program file: static.cpp // This program demonstrates dynamic and static variable allocation #include #include using namespace std; int accumulate1(int c); int accumulate2(int c); int main() { int count = 0; int sum1 = 0; int sum2 = 0; while (count < 5) { ++count; // same as count = count + 1 sum1 = accumulate1(count); sum2 = accumulate2(count); cout << count << " " << sum1 << " " << sum2 << endl; } system("pause"); return 0; } int accumulate1(int c) { int s = 0; // dynamic allocation of s s = s + c; return s; } int accumulate2(int c) { static int s = 0; // static allocation of s s = s + c; return s; }