03-pointer-fun/pointer_func.c
2024-10-05 12:35:38 +02:00

31 lines
No EOL
844 B
C

#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;
}