Pointer
- In Turkish
- İşaretçi
In short
A pointer is a variable that stores the memory address of another value instead of the value itself, letting code read or change that data indirectly.
What is a pointer?
A pointer is a variable whose value is a memory address, the location where some other piece of data lives. Instead of holding the number 42, a pointer holds something like "the number stored at address 0x7ffd1234". Reading or writing the value at that address through the pointer is called dereferencing it.
Pointers are most visible in C, C++, Zig and Go. In C, &x gives the address of x, and *p follows the pointer p to the value it points to. Pointers make it possible to pass large structures to functions without copying them, to build linked data structures such as linked lists and trees, and to work with memory requested from the heap. C also allows pointer arithmetic: adding 1 to a pointer moves it to the next element of an array.
A pointer is like a street address written on a slip of paper: the slip is small and cheap to copy, and anyone holding it can find the house. The danger is that the address can be wrong. A null pointer points nowhere, and a dangling pointer still holds the address of memory that has already been freed, so following either one can crash the program or open a security hole. Languages such as Java, Python and JavaScript hide raw addresses behind references managed by the runtime, and Rust checks at compile time that its references always point to valid data.
A pointer is often confused with a reference. Both let code reach a value indirectly, but a pointer is an explicit address you can inspect, reassign, set to null and sometimes do arithmetic on, while a reference is a more restricted alias managed by the language. In C++, a reference must be bound to an object when it is created and can't be pointed elsewhere later, and in Java every object variable is a reference, but there is no way to see or change the address itself.
Key takeaways
- A pointer stores a memory address rather than the data itself.
- Dereferencing a pointer reads or writes the value at that address.
- Pointers avoid copying large data and make linked data structures possible.
- Null and dangling pointers are a common source of crashes and security bugs.
- Many languages replace raw pointers with safer, runtime-managed references.
Example
#include <stdio.h>
void double_it(int *n) { // receives an address, not a copy
*n = *n * 2; // follow the pointer and change the original
}
int main(void) {
int score = 21;
int *p = &score; // & takes the address of score
double_it(p);
printf("%d\n", score); // prints 42
return 0;
}Readers ask
What is a null pointer?
A null pointer deliberately points to no valid memory, usually written as NULL in C or nullptr in C++. Dereferencing it is an error that typically crashes the program, so code must check for null before using a pointer that might be empty.
Do Python and Java have pointers?
Not in the C sense. Variables that hold objects in Python and Java are references: the runtime tracks where each object lives, but you can't read the raw address, do pointer arithmetic or free the memory yourself.
What is the difference between a pointer and a reference?
A pointer is an explicit memory address that can be changed, compared and set to null. A reference is a safer, more limited way of referring to a value that the language manages for you.
See also
- VariableProgramming Fundamentals, p. 56A variable is a named storage location in a program that holds a value, such as a number or a piece of text, which the code can read and change as it runs.
- CProgramming Languages, p. 3C is a compiled, low-level programming language that gives direct control over memory and is used to build operating systems, drivers, and embedded software.
- C++Programming Languages, p. 5C++ is a compiled, statically typed language that extends C with classes and templates while keeping low-level control over memory and performance.
- NullProgramming Fundamentals, p. 38Null is a special value that means "no value here", used when a variable deliberately refers to no object or data at all instead of holding something real.
- Memory LeakOperating Systems, p. 19A memory leak is a bug where a program keeps holding memory it no longer needs, so its memory usage grows over time and can slow down or crash the system.
- Linked ListData Structures, p. 22A linked list is a data structure that stores items in separate nodes, where each node holds a value and a reference to the next node in the chain.
Spotted a mistake or something missing on this page?Suggest an edit