A First Look at Pointers - C Pointer

C examples for Pointer:Introduction

Introduction

Point variable stores the address of a variable.

In general, a pointer of a given type is written type*.

You can declare a pointer to a variable of type int with the following statement:

int *pnumber;

The type of the variable with the name pnumber is int*.

It can store the address of any variable of type int.

You can also write the statement like this:

int* pnumber;

You can initialize pnumber so that it doesn't point to anything by rewriting the declaration like this:

int *pnumber = NULL;

NULL is a constant for zero value pointer.

NULL is a value that's guaranteed not to point to any location in memory.

To initialize your variable pnumber with the address of a variable, use the address of operator, &.

int number = 99;
int *pnumber = &number;

You can declare regular variables and pointers in the same statement, for example:

double value, *pVal, fnum;

Related Tutorials