Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96114
License: OTHER
1
/* Example code for Think OS.
2
3
Copyright 2014 Allen Downey
4
License: GNU GPLv3
5
6
*/
7
8
#include <stdio.h>
9
10
void f1() {
11
int i;
12
// int array[100];
13
float array[100];
14
15
for (i=0; i<100; i++) {
16
array[i] = i;
17
}
18
}
19
20
void f2() {
21
int x = 17;
22
int array[10];
23
int y = 123;
24
25
printf("%d\n", array[-2]);
26
printf("%d\n", array[-1]);
27
printf("%d\n", array[10]);
28
printf("%d\n", array[11]);
29
}
30
31
void f3() {
32
/* Read beyond the bounds of a string */
33
float x = 3.141592653;
34
char array[] = "allen";
35
36
printf("%c\n", array[-2]);
37
printf("%c\n", array[-1]);
38
}
39
40
void f4() {
41
char array[] = "Allen Downey";
42
float *p = array;
43
44
printf("%f\n", (double) *p);
45
}
46
47
int main()
48
{
49
// f1();
50
//f2();
51
//f3();
52
f4();
53
}
54
55
56