C Programming Tutorial 0/65 lessons ~6 min read Lesson 29

    Pointers

    A pointer variable records an address.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    A pointer variable records an address. With & and * you can link functions, arrays, and heap blocks without copying large payloads.

    Understanding the topic

    Declaration int *p; — p holds an address.

    Address-of & &x gives address of x.

    Dereference * *p gives value at address p.

    • Declaration — int *p; — p holds an address.
    • Address-of & — &x gives address of x.
    • Dereference * — *p gives value at address p.

    Step-by-step explanation

    1. Declaration — int *p; — p holds an address.
    2. Address-of & — &x gives address of x.
    3. Dereference * — *p gives value at address p.

    Syntax reference

    Syntax reference:

    c
    type *ptr;
    ptr = &variable;
    *ptr = value;

    Informative example

    Example program:

    c
    #include <stdio.h>
    int main(void) {
    int n = 17;
    int *ptr = &n;
    printf("val=%d at=%p\n", *ptr, (void*)ptr);
    return 0;
    }

    Execution workflow

    1Pointers — step by step
    1 / 3

    Declaration

    int *p; — p holds an address.

    Best practices

    • Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
    • Give every variable a defined value before it is read.
    • Stay inside array bounds — C will not stop you from over-running a buffer.

    Common mistakes

    • Reading uninitialized storage — behavior is undefined.
    • Dismissing compiler warnings instead of fixing root causes.
    • Ignoring NULL returns from malloc, fopen, and similar APIs.

    Hands-on exercise

    Practice problems:

    • Pointer to int
    • Modify value through pointer
    • Null pointer check

    Summary

    Pointers in C — Address variables that tie together memory, arrays, and functions.

    Ready to mark this lesson complete?Track your journey across the entire course.