understand static and extern

This commit is contained in:
2026-09-24 15:06:50 -07:00
parent 2ab485017c
commit a4ee663899
3 changed files with 30 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
extern int sum;
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
#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;
}
+8
View File
@@ -0,0 +1,8 @@
#include <stdio.h>
#include "helper.h"
int sum = 0;
void increment() {
sum++;
}