Lecture overview -- Keyboard shortcut: 'u'  Previous page: Fundamental types -- Keyboard shortcut: 'p'  Next page: Arrays and Pointers: Examples -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 1 - Page 14 : 29
Notes about C++
From C to C++
Arrays and Pointers

Arrays and pointers are closely related in C

The compiler translates all array notations to pointer notation

  • Array basics

    • Consecutive memory, elements of same type, fixed size after allocation, size known by the compiler

    • 0-based indexing, subscripting a[i], no range checking

  • Array limitations

    • Cannot be assigned to each other, cannot be passed by value, cannot be returned by value

    • In other words: value semantics is not used for arrays in C

  • Pointer basics

    • A pointer is an address

    • In C you can work on both a pointer and the object pointed to

      • Pointer arithmetic

    • For two different types T and S: T* is different from S*

    • A pointer is established by & (the address operator) and eliminated by * (the dereferencing operator)

    • Generic pointer type void*

    • NULL pointer value

  • Strings in C

    • A string is zero terminated, mutable char array

    • of type char[] or char*

    • "string-literals" - denoted with double quotes

    • Supported <string.h> standard library