From c2e5bdbf05f50ca495ed006be4155c8e196bc981 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 25 Jan 2017 00:03:01 -0700 Subject: [PATCH] Added: pass_value --- pass_value/main.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 pass_value/main.c diff --git a/pass_value/main.c b/pass_value/main.c new file mode 100644 index 0000000..a939773 --- /dev/null +++ b/pass_value/main.c @@ -0,0 +1,40 @@ +#include + + +void add_one(int *x); + +int main(void){ + + int j; + int *p; + int k; + + + j = 5; + + /* Pointer "p" is pointing to address "j" */ + p =&j; + /* Set k to the value of p + * the '*' is the dereference operater + * this means the value that p is pointing to + * instead of the pointer itself*/ + k = *p; + printf("%d\n", *p); + printf("This is k: %d\n", k); + + /*Here we pass the address of j to the function */ + add_one(p); + + /*Or don't use any pointers + * add_one(&j); + * + * here we pass by address value + */ + + printf("%d\n", *p); + return 0; +} + +void add_one(int *x){ + *x = *x+1; +}