For 64 bit systems, like most are these days, pointers will be 8-bytes or 64-bits. It is telling the compiler, “I have the address of a variable in the pointer.
The // declare an int pointer name ptr int *ptr; // declare an int with the value of 1 int val = 1; // get the address of the val variable and store it in ptr ptr = &val; // dereference the ptr variable to get the int value at the address stored int deref = *ptr; // dereference the ptr variable to set the int value at the address stored *ptr = 2; operator to get the address-of a variable of the correct type. I want to access that pointed-to address either to get a value or set a value “.
A pointer holds a reference to a variable; the reference being the memory address stored in the pointer.
When we access the value at that reference, we de-reference the pointer.
Declaring a pointer to be a specific type tells the compiler when the pointer is dereferenced the value pointed to will be of that type.
You will notice in the example above we declare a pointer type and then assign the address of a value of the same type.
For a compiler, a variable is a symbol for a starting memory address.
The compiler knows two things about any variable, the name and the type. Back when C was created, computers were much slower. Programmers needed to be much more efficient at solving problmes.
Dereferencing can be used to either indirectly get a value from the pointer address or to assign a value to the pointer address. In this example we have used dereferencing to both get and set values.
Some people get confused and think dereference means getting a value. Dereference means to indirectly access the address stored in the pointer.