

Pointer Variables (or Pointers)Ī pointer variable (or pointer in short) is basically the same as the other variables, which can store a piece of data. The following diagram illustrate the relationship between computers' memory address and content and variable's name, type and value used by the programmers. To store a 32-bit address, 4 memory locations are required.

A 32-bit system typically uses 32-bit addresses. A 4-byte int value occupies 4 memory locations.

Also, types (such as int, double, char) are associated with the contents for ease of interpretation of data.Įach address location typically hold 8-bit (i.e., 1-byte) of data. Instead of numerical addresses, names (or identifiers) are attached to certain addresses.

A variable is a named location that can store a value of a particular type. To ease the burden of programming using numerical address and programmer-interpreted data, early programming languages (such as C) introduce the concept of variables. It is entirely up to the programmer to interpret the meaning of the data, such as integer, real number, characters or strings. Typically, each address location holds 8-bit (i.e., 1-byte) of data. The address is a numerical number (often expressed in hexadecimal), which is hard for programmers to use directly. Pointer VariablesĪ computer memory location has an address and holds a content. Pointer is probably not meant for novices and dummies. Many new languages (such as Java and C#) remove pointer from their syntax to avoid the pitfalls of pointers, by providing automatic memory management.Īlthough you can write C/C++ programs without using pointers, however, it is difficult not to mention pointer in teaching C/C++ language. On the other hand, using them incorrectly could lead to many problems, from un-readable and un-maintainable codes, to infamous bugs such as memory leaks and buffer overflow, which may expose your system to hacking. Using them correctly, they could greatly improve the efficiency and performance. But they are also extremely complex to handle. Pointers are extremely powerful because they allows you to access addresses and manipulate their contents. However, "pointer" is also the most complex and difficult feature in C/C++ language. Pointers, References and Dynamic Memory Allocation are the most powerful features in C/C++ language, which allows programmers to directly manipulate memory to efficiently manage the memory - the most critical and scarce resource in computer - for best performance.
