Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

pointer-basics

Pointer basics

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Pointer basics: the syntax, patterns, and safety habits you need before advancing in C.

Pointers and dynamic allocation are the heart of C interviews—segfaults and leaks come from misunderstanding ownership.

You will apply Pointer basics in contexts like: Custom allocators, linked structures, and hand-off APIs in systems libraries.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true). Also never return addresses of local variables from functions.

When you can explain the previous lesson's ideas without copying starter code.

A pointer holds the address of another object. The address-of operator & and dereference operator * are central to C—compare with references in Rust or object references in Java, but without automatic safety checks.

Declaration and use

int value = 10;
int *ptr = &value;   /* ptr stores address of value */
*ptr = 20;           /* writes through pointer */

Null pointers

Initialize unused pointers to NULL (from stddef.h). Always check before dereferencing pointers that might be null.

Important interview questions and answers

  1. Q: What is NULL?
    A: A null pointer constant representing no object—dereferencing it is undefined behavior.
  2. Q: int* p vs int *p?
    A: Same meaning; style guides differ—be consistent: int *p emphasizes that *p is an int.
  3. Q: Why use pointers?
    A: Modify caller data, avoid copying large structs, dynamic allocation, and data structures like linked lists.

Self-check

  1. What operator gets an address?
  2. What operator reads through a pointer?

Pitfall: Dereferencing uninitialized or NULL pointers crashes or triggers undefined behavior—compare with Java where null checks throw NPE instead of UB.

Interview prep

What is NULL?

A null pointer constant representing no object; dereferencing it is undefined behavior.

Why use pointers?

Modify caller data, avoid copying large structs, dynamic allocation, and build linked data structures.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • NULL vs nullptr?
  • Dereference crash?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump