-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path09-StaticAndAuto.c
51 lines (36 loc) · 1.12 KB
/
09-StaticAndAuto.c
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
51
#include<stdio.h>
void count_calls(){ // what are the args?
// Declare an auto variable
auto int auto_ctr = 0;
// Declare a static variable
static int static_ctr = 0;
auto_ctr++;
static_ctr++;
printf("\nStatic %d", static_ctr);
printf("\nAuto %d", auto_ctr);
// Return both values (by reference)
}
void main(){
int auto_cnt;
int static_cnt;
int ctr;
// Can I access the static variable -- static_ctr;
printf("\nCALL 1\n");
count_calls(&auto_cnt, &static_cnt);
ctr++;
printf("Auto Count: %d\n", auto_cnt);
printf("Static Count: %d\n", static_cnt);
printf("\n--<Static %d", static_ctr);
printf("\nCALL 2\n");
count_calls(&auto_cnt, &static_cnt);
printf("Auto Count: %d\n", auto_cnt);
printf("Static Count: %d\n", static_cnt);
printf("\nCALL 3\n");
count_calls(&auto_cnt, &static_cnt);
printf("Auto Count: %d\n", auto_cnt);
printf("Static Count: %d\n", static_cnt);
printf("\nCALL 4\n");
count_calls(&auto_cnt, &static_cnt);
printf("Auto Count: %d\n", auto_cnt);
printf("Static Count: %d\n", static_cnt);
}