C / C++ / C#

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

C Tutorial - Advanced Pointers

By David Bolton, About.com

4 of 8

More about Example 1

The function sprintf() is like printf but outputs the text string to a specified buffer. It's used to build a key in the 16 character buffer variable key. As a proof that the list built and populated successfully you can call the findkey function or uncomment printList(). Both use a while loop which starts at the head and loops through the entire list.

Finally the killList() function frees up all of the memory in the list. The great thing with pointers is that you are free to construct sophisticated and complex data storage methods according to your needs. Let me say though, that apart from the interesting exercise of writing your own, there are several open source or free libraries that have well tested code and you may save considerable time (and hair) not having to debug your own. I've added one set (ubiqx) to the C code library.

Data Structures

This list is useful for storing items in memory and processing them by one by one. It's not so good say for accessing any individual element directly (called random access) as getting an element out of the list requires that you have to count forward from the head which slows it down. You could add this functionality by creating an index array of pointers and as each element is added to the list, use the id to store each element's address in this array.

It really depends on how you intend to use the storage- do you want random or serial access, fast addition and removal of elements etc? This is where the different storage data structures can be used. Some databases use binary trees for fast access.

On the next page : Function Pointers

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. More about Example 1

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

All rights reserved.