C Pointer Basics

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is Pointer Basics?

A pointer variable holds an address. Its type tells the compiler what lives there: int *p points to an int. Pointers have a fixed size regardless of what they point to, and they should always be initialized, either to a valid address or to NULL.

Remember
int  x = 10;
int *p = &x;        /* p holds the address of x */
printf("%d", *p);   /* 10: value at that address */
int *q = NULL;      /* points to nothing */

Cheat Sheet

Keep these facts handy while you work with Pointer Basics in C.

TopicDetail
Declaretype *name;
Initialize= &var; or = NULL;
SizeSame for all pointer types (typically 8 bytes)
Print an addressprintf("%p", (void *)p);

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Address and Dereference.

Example 1 — A pointer and its target

Two names for one object.

C
#include <stdio.h>

int main(void) {
    int score = 90;
    int *ptr = &score;

    printf("score = %d\n", score);
    printf("*ptr  = %d\n", *ptr);
    printf("same object: %d\n", ptr == &score);

    *ptr = 95;
    printf("score after = %d\n", score);
    return 0;
}

How It Works

  1. ptr stores the address of score.
  2. ptr == &score compares two addresses, so it is 1.
  3. Writing through *ptr changes score.

Edge Cases & Pitfalls

Check these before relying on Pointer Basics in real programs.

star

int* a, b;

Only a is a pointer here; b is a plain int. Declare one pointer per line.

uninit

Using an uninitialized pointer

int *p; *p = 5; writes to a random location.

Key Takeaways

  • Pointer: stores an address.
  • Type: tells what it points to.
  • Initialize: always.

One line: A pointer variable holds an address.

Frequently Asked Questions

It declares p as a pointer to int: a variable that can hold the address of an int.
Yes, cast to void * and use %p. The exact text of an address varies between runs.
Continue with "C Address and Dereference" next. Use & to get an address and * to follow it. The C Pointers hub lists every topic in order.

Next: Address and Dereference

Use & to get an address and * to follow it.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful