Here is a basic C program about pointers:
#include <stdio.h>
int main() {
int variable = 20;
int *pointerToVariable;
pointerToVariable = &variable;
printf("Address of variable: %x\n", &variable);
printf("Address of variable: %x\n", pointerToVariable);
printf("Address of variable: %x\n", *pointerToVariable); // * is the DEREFERENCING OPERATOR/INDIRECTION OPERATOR in C.
//It gives the value stored at the memory address
//stored in the variable which is its operand.
getchar();
return 0;
}
This produces the following output:
Address of variable: 8ffbe4
Address of variable: 8ffbe4
Address of variable: 14
But *pointerToVariable
should print 20, shouldn't it? Because *
gives the actual value stored at the memory address stored in its operand, right?
What am I missing?