Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96117
License: OTHER
1
/* Example code for Think OS.
2
3
Copyright 2015 Allen Downey
4
License: Creative Commons Attribution-ShareAlike 3.0
5
6
*/
7
8
#include <stdio.h>
9
#include <stdlib.h>
10
11
int global = 0;
12
13
int times_called()
14
{
15
static int counter = 0;
16
printf ("Address of counter is %p\n", &counter);
17
counter++;
18
return counter;
19
}
20
21
int main ()
22
{
23
int i, x;
24
int local = 5;
25
void *p = malloc(128);
26
27
printf ("Address of main is %p\n", main);
28
printf ("Address of global is %p\n", &global);
29
printf ("Address of local is %p\n", &local);
30
printf ("Address of p is %p\n", p);
31
32
for (i=0; i<3; i++) {
33
x = times_called();
34
printf("%d\n", x);
35
}
36
37
return 0;
38
}
39
40