Code works as described

This commit is contained in:
MarcUs7i 2024-10-05 12:35:38 +02:00
parent 0a62ab2a30
commit ae90c874c3
2 changed files with 31 additions and 0 deletions

31
pointer_func.c Normal file
View file

@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
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;
}