Bitpath

Lesson 1 · Unit 02

Addresses and pointers

Memory is a numbered row of bytes

12 exercisesabout 3 min

What you practise

  • Memory as an array of bytes, a pointer is an index, sizes of common types, Python names are references (id, aliasing)

Try a question from this lesson

Pick one

Memory is a long row of bytes, numbered from 0. A 4-byte integer is stored starting at byte 1000. Where does the next free byte start?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Every byte has an address

The number of a byte is its address. A value bigger than one byte takes neighbouring addresses and is named by its first one.

A pointer (or reference) is just an address stored as a value: a note saying "the data is over there".

address   1000  1001  1002  1003  1004
value    [ 2A ][ 00 ][ 00 ][ 00 ][ .. ]
         '---- one 4-byte int ----'

Concept

A pointer is an address

C lets you handle addresses directly. &x means "the address of x". *p means "the value at the address in p".

Writing through a pointer changes the original, because both names lead to the same bytes.

C
int x = 42;
int *p = &x;   // p holds x's address
*p = 7;        // write to that address
// x is now 7

9 more exercises in the app

  • 3× type the answer
  • 3× multiple choice
  • 1× true or false
  • 1× fill the blanks
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy