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
| /* Author: Marcos Azevedo (psylinux@gmail.com)
* Date: 2019-12-13
* Last Modified: 2019-12-17
* Description: Using the storage classes extern */
#include<stdio.h>
/* The lifetime of a global variable will be the same as the program
* gVar is initialized with zero */
int gVar;
void test2(){
/* If we do not explicitly initialize the variable, this content can be
* garbage. The lifetime is just within the function scope. */
int k;
printf("k = %d\n", k);
k = 20;
printf("k = %d\n", k);
gVar = 10;
printf("Inside test2: = %d\n", gVar);
}
void test1(){
/* The lifetime of this variable will be the same as the program
* var is initialized with zero */
static int var;
printf("var = %d\n", var);
var++;
printf("var = %d\n", var);
gVar = 20;
printf("Inside test1: gVar = %d\n", gVar);
}
int main(){
printf("#Inside Main: gVar = %d\n", gVar);
test2();
test1();
printf("#Inside Main: gVar = %d\n", gVar);
return 0;
}
|