diff options
Diffstat (limited to 'scope_tutorial')
-rw-r--r-- | scope_tutorial/1.c | 43 | ||||
-rw-r--r-- | scope_tutorial/2.c | 15 | ||||
-rw-r--r-- | scope_tutorial/2.o | bin | 0 -> 536 bytes | |||
-rw-r--r-- | scope_tutorial/Makefile | 2 | ||||
-rwxr-xr-x | scope_tutorial/a.out | bin | 0 -> 33666 bytes | |||
-rw-r--r-- | scope_tutorial/header.h | 4 |
6 files changed, 64 insertions, 0 deletions
diff --git a/scope_tutorial/1.c b/scope_tutorial/1.c new file mode 100644 index 0000000..fe38a56 --- /dev/null +++ b/scope_tutorial/1.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include "header.h" + +int hello_num(int, int); +int a = 0; +int b = 0; + +int main(void) +{ + int num = 1; + + { + int num = 2; + } + + auto double result; + +// double result2 = product_again(1,2); //results in error if uncommented because this function is specific to the file it was defined in + int value = use_another_static_function(7, 3); + + result = product(1,2); + + int newNum = hello_num(1,2); + + printf("Newnum is: %d\na is: %d\tb is %d\n", newNum,a,b); + + printf("result is: %lf\n", result); + + printf("num is: %d\n", num); + + printf("use_another_static_function(7,3) returns: %d\n", value); + + return 0; +} + + +int hello_num(int a, int b) +{ + a++; + ++b; + + return a; +} diff --git a/scope_tutorial/2.c b/scope_tutorial/2.c new file mode 100644 index 0000000..a9f9429 --- /dev/null +++ b/scope_tutorial/2.c @@ -0,0 +1,15 @@ +double product(double a, double b) +{ + return a * b; +} + +static double double_product(double a) +{ + return a * 2; +} + + +double use_another_static_function(double a, double b) +{ + return double_product(product(a, b)); +} diff --git a/scope_tutorial/2.o b/scope_tutorial/2.o Binary files differnew file mode 100644 index 0000000..53a371e --- /dev/null +++ b/scope_tutorial/2.o diff --git a/scope_tutorial/Makefile b/scope_tutorial/Makefile new file mode 100644 index 0000000..929801f --- /dev/null +++ b/scope_tutorial/Makefile @@ -0,0 +1,2 @@ +simple: + gcc 1.c 2.c && ./a.out diff --git a/scope_tutorial/a.out b/scope_tutorial/a.out Binary files differnew file mode 100755 index 0000000..4e413d3 --- /dev/null +++ b/scope_tutorial/a.out diff --git a/scope_tutorial/header.h b/scope_tutorial/header.h new file mode 100644 index 0000000..21761c0 --- /dev/null +++ b/scope_tutorial/header.h @@ -0,0 +1,4 @@ +double product(double a, double b); + +double product_again(double a, double b); //only for educational purposes, serves no real purpose as product again has internal linkage +double use_another_static_function(double a, double b); |