Everything you need to know about pointers in C (2010)

  • The time [0] I found out about ptr_b in

      int* ptr_a, ptr_b;
    
    isn't actually initialized as a pointer I changed all my C code to marking * before the variable name, fun times. It's helpful to think int as the base type and * the indicator of functionality like [] and ().

    Also just found out the author was the developer of Adium [1], which is one of my favorite softwares (best logo) on macOS.

    [0] http://c-faq.com/decl/charstarws.html

    [1] https://adium.im/

  • > void pointers are incremented or decremented by 1 byte.

    No, void pointer arithmetic is not allowed by the C standard: https://stackoverflow.com/questions/3523145/pointer-arithmet...

  • By C half-assedly trying to make "* " part of the name, just so you can use "* ptr" everywhere like it is an actual variable name, you get confusions such as this.

    First "foo_ptr's type is int * ", but then "The pointer has a type, too, by the way. Its type is int.".

    I also refuse to agree with "An int * * 's type is int * ". :)

    But I guess "the type of `* ptr` is int, the type of `ptr` is int * " would be even more confusing.

  • int array[] = {...}

    1[array] == array[1]

    Now add in some poorly named variables for some real fun

    https://github.com/Droogans/unmaintainable-code#cs-eccentric...

  • > A pointer is a memory address.

    This is an amazingly wrong statement. In assembly you deal with memory addresses. Pointers in C are a much higher level abstraction.

    > On current mainstream Intel processors, it occupies four bytes of memory (because an int is four bytes wide).

    This depends on the compiler as well as the processor.