#include <iostream> using namespace std; void addprint() { static int s = 1; s++; cout << s; } int main() { addprint(); addprint(); addprint(); return 0; }
a) 234
b) 111
c) 123
d) 235
#include <iostream> using namespace std; void addprint() { static int s = 1; s++; cout << s; } int main() { addprint(); addprint(); addprint(); return 0; }
a) 234
b) 111
c) 123
d) 235
You must be logged in to post a comment.
a
Explanation: The variable that is declared as static has a file scope.
Output:
$ g++ dec2.cpp
$ a.out
234