References and DereferencesReferences and Dereferences

The concept of pointers is based on two unary (one-character) operators:

  • reference operator &;
  • dereference operator *.

Reference operator

This operator allows us, literally, to feel the RAM of our computer. The & operator allows you to get the actual address of an object.

c

Main.c

Note

%p is a specifier for addresses (pointer).

The object address is written in hexadecimal notation:

The & operator recognizes your address from your name.

Dereferences operator

On the contrary, the * operator returns the name of the house's owner at his address. But how can we use this operator when not directly working with addresses? The &x expression returns the address of the x variable, if you use the * operator on the &x expression, then we will get the value of the variable that is hidden behind this address:

c

Main.c

Note

Do not confuse the dereference operator (*x) with the multiplication operator (x*y).

Task

  1. Create an integer array with 5 elements and fill it.
  2. Return the address of the third element.
  3. Add one to the address of the third element (address + 1).
  4. Try to dereference the address received in the 3rd task

Everything was clear?

Section 6. Chapter 2
toggle bottom row