Skip over navigation

What Are Pointers?

Pointer Syntax


Pointer Syntax, page 2

page 1 of 3

So you want a pointer, huh?

Pointer syntax, though relatively straightforward, can be confusing at first.

Before we can use a pointer, the first thing we need is a pointer itself, so how do we declare one? Declaration of a pointer is done just like any other variable:

int *steve;

If you look at the declaration above, you'll notice that it looks the same as a declaration of an int, with the exception of the asterisk (*) in front of steve. The asterisk is used in a variable declaration to tell the computer we'd like a pointer. In the above case, we're asking the computer for a pointer variable, named steve that can point to a integer. To compare: int steve -> steve is an integer variable int *steve -> steve is a pointer variable that can point to an integer variable

Let's look at some more:

Declaration What it means
int steve steve is an integer
int *steve steve is a pointer to an integer
char steve steve is a character
char *steve steve is a pointer to a character
long steve steve is a long integer
long *steve steve is a pointer to a long integer
unsigned char steve steve is an unsigned character
unsigned char *steve steve is a pointer to an unsigned character

But pointers can point to more than just the simple data types like integers and characters. We can have pointers to numerous instances of a data type. In fact, this is so common that it is given a separate name (an array) and a separate syntax. See the Arrays SparkNote for details on the use of arrays.

In addition, we can declare pointers to data types that we define ourselves:

typedef struct _person_t {
	char name[100];
	int age;
} person_t;

person_t *steve;
Here, steve is a pointer to a variable of type person_t.

Follow Us