I think that I have the basic concept of pointers pretty clear now (after considering it, reading and re-watching the course material a few times) but I still have a question.
A pointer is essentially a new type of variable which stores the location in memory of some data. The type of pointer also tells the compiler how to treat the data at that location. So that, for example, with regards to an
int*, when dereferenced, the compiler will look at the first 4 bytes at that location and interpret the ones and zeroes as an int, whereas with regards to a
char*, when dereferenced, the compiler will look at only the first byte at that location and interpret the ones and zeroes as a char.
But that leads me to my question. If so, what's the difference between an
int* and an
int (for example)? Meaning, let's say that my program creates and initializes an
int (for example
int x = 5;). It's not like the compiler treats
x as if
x were a macro and replaces
x with 5 wherever
x turns up. Instead there's probably a lookup table somewhere which stores the address of
x and whenever the compiler sees
x it looks up that address and dereferences it. If so, does that mean that every variable is really a pointer? Am I making a mistake?
If I am not, then the logical consequences are: (1) Every variable is in fact a pointer. (2) Whenever you refer to a variable in your code the compiler automatically deferences it.