Log in Sign up
Back to Discover
💻

Pointer (computer programming)

technology Maturity 7-9

A pointer is like a sign.

Pointers.svg
Pointers.svg
It points to a spot in a computer. It tells the computer where to look. This helps the computer work fast. It is a very smart tool. Do you like to follow signs?

40 words

A pointer is like a sign.

Pointers.svg
Pointers.svg
It tells a computer where to look. It holds a special number. This number is an address.

Think of a book index. The index has a page number. That number is like a pointer. You look at the number to find a page.

When you follow the pointer, it is called dereferencing. You go to the spot to find the data. This helps computers work very fast.

Sometimes, a pointer points to a wrong spot. This can make a program crash. It is a powerful tool.

Computers use these to move data around. They help keep things organized. It is a smart way to work.

112 words

A pointer is a special tool in computer programming.

Pointers.svg
Pointers.svg
It does not hold data like a number or a word. Instead, it stores a memory address. A memory address is a location where data lives. You can think of a pointer like a page number in a book index. The index tells you where to go. To find the info, you must flip to that page. This step is called dereferencing. When you dereference a pointer, you go to its address to find the value stored there.

Using pointers helps computers work much faster. It is often quicker to move a pointer than to copy big pieces of data. Pointers help build complex parts like linked lists or trees. These are ways to organize data in a chain or a web.

However, pointers can be tricky. If a pointer points to a wrong or empty spot, the program might crash. This is why programmers must be careful. In 1964, Harold Lawson is credited with inventing the pointer. He helped bring this idea to the PL/I language. This made it easier to handle data in many ways.

187 words

A pointer is a special tool used in computer programming.

Pointers.svg
Pointers.svg
It does not store a simple value like a number or a letter. Instead, a pointer stores a memory address. A memory address is a specific location where data lives in a computer. You can think of a pointer like a page number in a book's index. The index tells you where to find information. To find that information, you must flip to the correct page. This step is called dereferencing the pointer.
Pointers.svg
Pointers.svg

How a pointer works is a very useful thing that happens in a computer. First, the pointer holds the address of a piece of data. Next, the computer uses that address to find the exact spot in its memory. Then, it can read or change the data at that spot. This is called a level of indirection. It is often much faster to move a small pointer than to copy a huge amount of data. Using pointers makes repetitive tasks, like moving through lists, work much better.

Pointers.svg
Pointers.svg

There is an interesting history behind this idea. In 1955, a scientist named Kateryna Yushchenko created the Address programming language. This language allowed for something very similar to pointers. However, her work was mostly known within the Soviet Union. Most people credit Harold Lawson with inventing the pointer variable. In 1964, he introduced this concept into the PL/I language. This allowed programmers to work with linked lists more easily.

Pointers.svg
Pointers.svg
Because of his work, Lawson received the Computer Pioneer Award in 2000.

Computers use many different types of data to function. A byte is the smallest piece of data a computer can read. Every memory address points to a different byte. Sometimes, a group of bytes is joined together to make a larger piece of data. This group is called an aggregate. A pointer is a type of primitive, which is a simple piece of data. The format of a pointer depends on the computer's architecture.

Pointers.svg
Pointers.svg
For example, some pointers are 64 bits long.

While pointers are helpful, they can also cause big problems. If a pointer tries to look up an address that does not exist, the program might crash. This is sometimes called a segmentation fault. Programmers must be very careful when they use them. If they forget to clean up memory after using a pointer, it can cause a memory leak. This happens when a computer slowly runs out of free memory. However, when used correctly, pointers are a fundamental part of how modern software works.

Pointers.svg
Pointers.svg

424 words

In computer science, a pointer is a fundamental object used in many programming languages. Instead of storing a direct value like a number or a character, a pointer stores a memory address. This address serves as a reference to a location in the computer's memory. That location might hold another value or even represent memory-mapped computer hardware.

Pointers.svg
Pointers.svg
By using pointers, programmers can access data through a level of indirection. This means the pointer's value determines which specific memory address will be used in a calculation. This mechanism is essential for creating complex data structures and managing how software interacts with hardware.

To understand how a pointer works, one must understand the process of dereferencing. A pointer holds a specific numeric index, which is the memory address. When a program needs the actual data, it performs an operation called dereferencing. This means the computer looks up the value stored at the address held by the pointer.

Pointers.svg
Pointers.svg
You can compare this to a book's index. The index provides a page number, which acts as a pointer. Flipping to that page to read the text is the equivalent of dereferencing. This process allows for much more efficient data handling. It is often much cheaper in terms of time and space to copy a small pointer than to copy the entire data set it references.

Computer memory is organized into different types of data units. A data primitive is any datum that can be read or written using a single memory access. A byte is considered the smallest primitive, and every memory address specifies a different byte. When several primitives are grouped together logically in memory, they form a data aggregate.

Pointers.svg
Pointers.svg
If an aggregate is made entirely of the same type of primitive, it is called an array. A pointer is itself a primitive, but its value is intended to be interpreted as a memory address. In many systems, the format and content of a pointer variable depend entirely on the underlying computer architecture.

There is an interesting history regarding the development of these tools. In 1955, the Soviet Ukrainian scientist Kateryna Yushchenko created the Address programming language. This language enabled indirect addressing and high-rank addresses, which are analogous to modern pointers. While this was widely used on Soviet computers, it remained largely unknown outside the Soviet Union. Most historians credit Harold Lawson with the invention of the pointer variable. In 1964, Lawson introduced the concept into the PL/I language.

Pointers.svg
Pointers.svg
This allowed for the flexible treatment of linked lists in high-level languages. For this achievement, Lawson received the Computer Pioneer Award from the IEEE in 2000.

Using pointers provides significant performance advantages for specific tasks. They are highly effective for traversing iterable data structures. These structures include strings, lookup tables, control tables, linked lists, and tree structures. Pointers are also used to hold entry points for subroutines in procedural programming. In object-oriented programming, pointers to functions are used for binding methods, often through virtual method tables.

Pointers.svg
Pointers.svg
They also allow for run-time linking to dynamic link libraries, also known as DLLs. Without pointers, managing these complex, interconnected systems would be much slower and more difficult.

However, pointers also introduce specific risks to a computer system. Because they allow both protected and unprotected access to memory, they can be dangerous if used incorrectly. If a program attempts to dereference a pointer containing an invalid memory address, the program may crash. On certain platforms, such as the Intel x86 architecture, this is called a segmentation fault, or a segfault.

Pointers.svg
Pointers.svg
Other architectures, like AMD64, use 64-bit pointers but only support addresses up to 48 bits. If a non-canonical pointer is used, the processor may raise a general protection fault. To prevent these issues, many languages use type safety or validation to ensure a pointer stays within a valid numerical range.

Beyond simple data storage, pointers are vital for memory management. Programmers use them to allocate and deallocate dynamic variables and arrays. If a programmer fails to deallocate memory that is no longer needed, a memory leak can occur. This happens when available free memory gradually or rapidly diminishes because redundant blocks are not cleared.

Pointers.svg
Pointers.svg
Pointers also allow for passing parameters by reference. This means a function can modify a parameter so that the changes are visible to the original caller. This technique is also useful for allowing a function to return multiple values. By connecting different parts of a program, pointers serve as the invisible threads that hold complex software together.

750 words
🖼️ Images & Media (1)
File:Pointers.svg
Pointers.svg
Up Next
💻
Data structure
Technology
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.