From a4ee663899b4301052c47156ad17ce42f98e315b Mon Sep 17 00:00:00 2001 From: talksik Date: Thu, 24 Sep 2026 15:06:50 -0700 Subject: [PATCH] understand static and extern --- ch4/helper.h | 3 +++ ch4/main.c | 19 +++++++++++++++++++ ch4/other.c | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 ch4/helper.h create mode 100644 ch4/main.c create mode 100644 ch4/other.c diff --git a/ch4/helper.h b/ch4/helper.h new file mode 100644 index 0000000..ca17d75 --- /dev/null +++ b/ch4/helper.h @@ -0,0 +1,3 @@ + + +extern int sum; diff --git a/ch4/main.c b/ch4/main.c new file mode 100644 index 0000000..3452ddc --- /dev/null +++ b/ch4/main.c @@ -0,0 +1,19 @@ +#include +#include "helper.h" + +void increment(); + +int main() { + printf("hello world\n"); + + increment(); + increment(); + + printf("sum within main: %d\n", sum); + + sum++; + + printf("sum within main: %d\n", sum); + + return 0; +} diff --git a/ch4/other.c b/ch4/other.c new file mode 100644 index 0000000..a94971f --- /dev/null +++ b/ch4/other.c @@ -0,0 +1,8 @@ +#include +#include "helper.h" + +int sum = 0; + +void increment() { + sum++; +}