From a96533946ffbab774af0a1ffb08e2eeb61d1fe59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20G=C3=B6r?= Date: Wed, 30 Oct 2024 09:04:32 +0300 Subject: [PATCH] scope examples --- ChangeLog | 2 ++ c-basic/global_scope.c | 19 +++++++++++++++++++ c-basic/scope.c | 2 -- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 c-basic/global_scope.c diff --git a/ChangeLog b/ChangeLog index 40fd64f..5ff6705 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2024-10-30 Mert Gör + * c-basic/C.pdf: Global variable scope page 26 + * c-basic/scope.c (foo): same variable different scopes * c-basic/C.pdf: page 25,end of the page diff --git a/c-basic/global_scope.c b/c-basic/global_scope.c new file mode 100644 index 0000000..10a8f2e --- /dev/null +++ b/c-basic/global_scope.c @@ -0,0 +1,19 @@ +#include + +int main() +{ + int a; + + a = 10; + + { + int a; + + a = 20; + printf("%d\n", a); // 20 + } + + printf("%d\n", a); // 10 + + return 0; +} diff --git a/c-basic/scope.c b/c-basic/scope.c index 67e4a58..bcdd335 100644 --- a/c-basic/scope.c +++ b/c-basic/scope.c @@ -3,9 +3,7 @@ void foo() { int a; - { int a; - } } int main()