Pointers

Pointers are one of the most powerful features in C, and also the feature most likely to break something if misused!

#include <stdio.h>
int main(void)
{
    const char *choc_cake = "Chocolate Cake";   // a string literal
    const char *fork = choc_cake;               // fork points to cake

    printf("Fork is pointing at: %s\n", fork);

    // Now fork points to something else
    const char *carrot_cake = "Carrot Cake";
    fork = carrot_cake; 
    printf("Fork moved! Now pointing at: %s\n", fork);

    return 0;
}

Me when I first tried learning pointers

An ancient meme which shows my age.

Me when I tried learning pointers for the 20th time

An ancient meme which shows my age.


Table of contents