-
Notifications
You must be signed in to change notification settings - Fork 1
/
Storage.c
110 lines (72 loc) · 1.98 KB
/
Storage.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
int x;
void autoStorageClass()
{
printf("\nDemonstrating auto class\n\n");
auto int a = 32;
printf("Value of the variable 'a'"
" declared as auto: %d\n",
a);
printf("--------------------------------");
}
void registerStorageClass()
{
printf("\nDemonstrating register class\n\n");
register char b = 'G';
printf("Value of the variable 'b'"
" declared as register: %d\n",
b);
printf("--------------------------------");
}
void externStorageClass()
{
printf("\nDemonstrating extern class\n\n");
extern int x;
printf("Value of the variable 'x'"
" declared as extern: %d\n",
x);
x = 2;
printf("Modified value of the variable 'x'"
" declared as extern: %d\n",
x);
printf("--------------------------------");
}
void staticStorageClass()
{
int i = 0;
printf("\nDemonstrating static class\n\n");
printf("Declaring 'y' as static inside the loop.\n"
"But this declaration will occur only"
" once as 'y' is static.\n"
"If not, then every time the value of 'y' "
"will be the declared value 5"
" as in the case of variable 'p'\n");
printf("\nLoop started:\n");
for (i = 1; i < 5; i++)
{
static int y = 5;
int p = 10;
y++;
p++;
printf("\nThe value of 'y', "
"declared as static, in %d "
"iteration is %d\n",
i, y);
printf("The value of non-static variable 'p', "
"in %d iteration is %d\n",
i, p);
}
printf("\nLoop ended:\n");
printf("--------------------------------");
}
int main()
{
printf("A program to demonstrate"
" Storage Classes in C\n\n");
autoStorageClass();
registerStorageClass();
externStorageClass();
staticStorageClass();
printf("\n\nStorage Classes demonstrated");
return 0;
}