mikroC

making it simple...

mikroC - C Compiler for Microchip PIC microcontrollers

Note: You must initialize pointers before using them! Our previously declared pointer *p is not initialized (i.e. assigned a value), so it cannot be used yet.

Note: In case of multiple pointer declarations, each identifier requires an indirect operator. For example:

int *pa, *pb, *pc;

/* is same as: */

int *pa; int *pb; int *pc;

Once declared, though, a pointer can usually be reassigned so that it points to an object of another type. mikroC lets you reassign pointers without typecasting, but the compiler will warn you unless the pointer was originally declared to be pointing to void. You can assign a void pointer to a non-void pointer – refer to Void Type for details.

Null Pointers

A null pointer value is an address that is guaranteed to be different from any valid pointer in use in a program. Assigning the integer constant 0 to a pointer assigns a null pointer value to it. Instead of zero, the mnemonic NULL (defined in the standard library header files, such as stdio.h) can be used for legibility. All pointers can be successfully tested for equality or inequality to NULL.

For example:

int *pn = 0; /* Here's one null pointer */

int *pn =

NULL;

/* This is an equivalent declaration */

/* We can

test the pointer like this: */

if ( pn

== 0 ) { ... }

/*

.. or like this: */

if

( pn

==

NULL ) { ... }

 

 

page

MikroElektronika: Development tools - Books - Compilers

69