Skip to main content
3 of 4
added 306 characters in body
chqrlie
  • 152.1k
  • 12
  • 145
  • 231

Think of an array as a block of houses in a city and a pointer as a piece of paper with the GPS coordinates of the first house written on it.

The block cannot move, nor can you change its size. Houses can be built on the block (value assignment), which does not change the coordinates on the pointer.

The name of the street (array name) can be used to refer to a given house, but the coordinates are just as efficient, especially for someone who does not have a map (the array name is out of scope).

You can make the pointer point to another house by erasing the coordinates and writing different ones. Writing nothing is similar to making the pointer a null pointer.

Just looking at the pointer, you cannot tell how many houses are in the block.

You can put some pieces of paper in your pockets (CPU registers) or you can stick them on a wall (store them in memory)... At which point they have GPS coordinates you can write on a piece of paper (pointer to a pointer).

chqrlie
  • 152.1k
  • 12
  • 145
  • 231