Skip to content

Head first c

Chapter 2: Memory and Pointer

  • Use printf("%p", pointer); to print a pointer
  • Explain in easy-way to understand about Stack & Heap
  • sizeof()
    • is not a function, it's operator (?)
    • sizeof() is calculated in compile-time.
    • array & pointer is defference in sizeof()

Chapter 3

  • Explain about Standard Input and Output and how to redirect in Linux (uses '>' and '<'').
  • scanf() and printf() are two functions that use for communicate with STDIO.
  • Problem about editing a string:

    • In case a pointer points to constant string like this char *ptr = "JQK";. You can not modify string by *(ptr + i) = 'x'.
    • But when using array, you can: char ptr[] = "JQK".

    In first case, "JQK" is constant and be stored in a part of memory that you can not modify. In the second case, "JQK" stills is stored in this read-only memory but when you call char ptr[] = "JQK", another memory is allocate for array ptr and "JQK" will be coppied in there -> that can be modified.

Back to top