Introduction to Pointers
You might've worked with pointers before
The concept of pointers are unique to languages like C, C++, Rust etc., which gives explicit control to how the values are laid out in memory. In object oriented programming languages like Java, Scala, Python etc., every variable stores the address of the object(value) which will be laid out in heap memory, and they are called reference variables.
Definition of a pointer
A pointer is a variable which can store the address of a variable or value.
Examples
In short every pointer variable of arbitrary types requires only 64 bits to be stored in 64 bit architecture.
In computer memory every byte has a unique address. The address of a variable refers to the first byte of the value of that variable in memory. We can observe that these addresses are a runtime construct. When compilers compile our program it generates binary code which will be executed by the operating system later (we can write bare metal Rust also, but we are not concerned about this here). So every time the program is executed we will observe different memory address for the same variable.
Why Pointers are important?
Rust specific clarifications
The pointers that we have discussed so far are called shared references, which are Thin pointers. Because they are compiled in a way that they only store the address of a value. There are other kinds of pointers like smart pointers, fat pointers etc., which we will cover later in the course.
Last updated