I think this is a really easy thing to code, but I\'m having trouble with the syntax in C, I\'ve just programmed in C++.
#include
#include
To access the value that a pointer points to, you have to use the indirection operator *
.
To print the pointer itself, just access the pointer variable with no operator.
And to get the address of the pointer variable, use the &
operator.
void pointerFuncA(int* iptr){
/*Print the value pointed to by iptr*/
printf("Value: %x\n", *iptr );
/*Print the address pointed to by iptr*/
printf("Address of value: %p\n", (void*)iptr);
/*Print the address of iptr itself*/
printf("Address of iptr: %p\n", (void*)&iptr);
}
The %p
format operator requires the corresponding argument to be void*
, so it's necessary to cast the pointers to this type.