YouTube

Session 17 of Software Lessons, “Programming in C++: Namespaces, Pointers, References, Types, Values,” runs about 26 minutes.

What this session covers

  • Namespaces
  • Pointers, references and values in the context of the stack and heap
    • Memory address versus the value at that address
    • Pointers: point to a memory address
    • References: a pointer whose memory address cannot change
    • Values: just the value, not a memory address
  • Declaring versus defining variables
  • The standard C++ library
  • Preprocessing directives

Key ideas

  • A namespace groups names together so that identifiers from different libraries do not collide.
  • A pointer stores a memory address, and following the pointer gives you the value stored at that address.
  • A reference is another name for an existing object and, unlike a pointer, cannot be changed to refer to something else.
  • A declaration tells the compiler that a name exists and has a type, and a definition creates the thing itself.
  • Preprocessing directives such as #include are handled before compilation and are how code from the standard library and other files is brought in.