Home C Pointers Pointer Basics C Pointer Basics Definition
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.
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 */ Reference
Cheat Sheet Keep these facts handy while you work with Pointer Basics in C.
Topic Detail Declare type *name;Initialize = &var; or = NULL;Size Same for all pointer types (typically 8 bytes) Print an address printf("%p", (void *)p);
Code
C Examples Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Address and Dereference .
1. A pointer and its target Example 1 — A pointer and its target Two names for one object.
#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;
} score = 90
*ptr = 90
same object: 1
score after = 95 How It Works ptr stores the address of score.ptr == &score compares two addresses, so it is 1.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.
Remember
Key Takeaways One line: A pointer variable holds an address.
Frequently Asked Questions What does int *p mean? It declares p as a pointer to int: a variable that can hold the address of an int.
Can pointers be printed? Yes, cast to void * and use %p. The exact text of an address varies between runs.
What should I learn after Pointer Basics? 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.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion