-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic_experiment.cpp
More file actions
50 lines (43 loc) · 902 Bytes
/
static_experiment.cpp
File metadata and controls
50 lines (43 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
*
*
* @name static_experiment.cpp
*
* @version 1.0
* @date 01/22/2015 (01:53:46 PM)
* @revision none
* @compiler gcc
*
*
* @author P. Di Giglio (github.com/pdigiglio), <p.digiglio91@gmail.com>
* @company
* @brief
*
* Example usage:
* @code
* @endcode
*
*
*/
#include <iostream>
using namespace std;
/** XXX The value for a is the first assigned for each function */
int& foo( int b ) {
static int a = b;
cout << "foo: " << b << " " << a << endl;
return a;
}
int* bar( int b ) {
static int a = b;
cout << "bar: " << b << " " << a << endl;
return &a;
}
int main () {
for ( unsigned int c = 1; c < 10; ++ c ) {
cout << foo( c ) << " " << &foo(c) << endl;
}
for ( unsigned int a = 3; a < 10; ++ a ) {
cout << *bar( a ) << " " << bar(a) << endl;
}
return 0;
}