HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to CVariablesData TypesOperatorsStringsArraysConditions (if / switch)Loops (for / while)FunctionsPointers
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
👉 Pointer
Pointer ( * and & )Passing a pointer to a function
C›REFERENCE›Pointer
👉

Pointer

Working with memory addresses — the heart of C.

CommandDescription
Pointer ( * and & )Holds the address of a variable.
Passing a pointer to a functionAllowing a function to modify an external variable.

Pointer ( * and & )

Try it yourself →

Holds the address of a variable.

Syntax

type *p = &variable;

Description

& gives the ADDRESS of a variable; * accesses the VALUE at that address. Pointers are C's most powerful and demanding feature.

Example

#include <stdio.h>
int main() {
    int x = 10;
    int *p = &x;
    printf("%d\n", *p);
    *p = 20;
    printf("%d\n", x);
    return 0;
}

Expected output

10
20

When to use?

Passing data to a function by reference, dynamic memory, arrays.

Common mistakes

  • ⚠️ & gets the address, * accesses the value — don't mix them up.
  • ⚠️ Reading an uninitialized pointer (*p) causes a crash.

Passing a pointer to a function

Try it yourself →

Allowing a function to modify an external variable.

Syntax

void name(int *p) { *p = ...; }

Description

You enable a function to modify the original variable by passing its address (passing by reference).

Example

#include <stdio.h>
void doubleIt(int *p) {
    *p = *p * 2;
}
int main() {
    int x = 5;
    doubleIt(&x);
    printf("%d\n", x);
    return 0;
}

Expected output

10

When to use?

Returning multiple values from a function, passing large data without copying.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code