diff --git a/pointer_func b/pointer_func new file mode 100644 index 0000000..3bdc914 Binary files /dev/null and b/pointer_func differ diff --git a/pointer_func.c b/pointer_func.c new file mode 100644 index 0000000..a3967ee --- /dev/null +++ b/pointer_func.c @@ -0,0 +1,31 @@ +#include +#include + +void print_integers(int int_value, int* int_pointer) +{ + printf("Got an integer value %d and an address to an integer with value %p\n", int_value, (void*)int_pointer); +} + +void change_integers(int int_value, int* int_pointer) +{ + int_value = 23; + *int_pointer = int_value; +} + +int main(int argc, char* argv[]) +{ + int int_value; + int* int_pointer; + + int_value = 42; + int_pointer = &int_value; + //to point to a variable, we need to use here the '&' symbol before a variable, to get it's address. + + print_integers(int_value, int_pointer); + + change_integers(int_value, int_pointer); + print_integers(int_value, int_pointer); + //only, the value in the int_value changed, because we change it. But the address can't be changed, because we only change it's value. + + return 0; +} \ No newline at end of file