C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

C Tutorial - Advanced Pointers

By David Bolton, About.com

1 of 8

Storing Data in RAM

When you write an application, unless it is trivial, one of the first problems you need to think about is how to hold data in memory. Your application may use a database but you will probably need some way to handle the data in memory.

One way to hold it is in an array of structs, unless the data is particularly complicated like in a text editor, word processor, or a web server. What it really means is that you need a dynamic storage method not a static one. Arrays in C for example are static. You specify how big each element is and how many there are. If it's too big for what was needed you've wasted space. Too small and your application will probably go into a permanent sulk sometime- i.e. it will crash.

Pointers are the Answer

More modern languages such as C# or Java offer libraries of advanced data structures and even C++ has the STL types like vector etc. There are a considerable number of dynamic storage methods possible- not just dynamics arrays - but jagged arrays, sparse arrays, index sequential, maps, trees, queues etc. Do you need a list that you can process randomly or just serially (element one then element two etc)? Those are the stuff of much more advanced tutorials but this lesson will start by showing how to build and use a single linked list.

About Linked Lists

A linked list a bunch of structs all connected by pointers. There are basically two types of linked lists: single and double. In a single linked list (shown), each node in the list is a struct and contains data plus a pointer to the next node. In a double linked list, each node has two pointers not one- one to the next node and one to the previous. It's also possible to hook up the ends of a double linked list to make a circular linked list.

On the next page : Example 1 - A Linked List Implementation

Explore C / C++ / C#

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

C / C++ / C#

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C
  5. C Tutorials
  6. C Tutorial - Advanced Pointers

©2009 About.com, a part of The New York Times Company.

All rights reserved.