mikroElektronika PIC Microcontrollers PIC12 User Manual page 80

Mikroc user's manual
Table of Contents

Advertisement

mikroC - C Compiler for Microchip PIC microcontrollers
You can also compare pointers to zero value – this tests if pointer actually points
to anything. All pointers can be successfully tested for equality or inequality to
NULL:
if (pa == NULL) { ... }
if (pb != NULL) { ... }
Note: Comparing pointers pointing to different objects/arrays can be performed at
programmer's responsibility — precise overview of data's physical storage is
required.
Pointer Addition
You can use operators
result of addition is defined only if pointer points to an element of an array and if
the result is a pointer pointing into the same array (or one element beyond it).
If a pointer is declared to point to
advances the pointer by that number of objects of type. Informally, you can think
of
P+n
pointer remains within the legal range (first element to one beyond the last ele-
ment). If
the pointer 50 bytes in memory. In case of
For example:
int a[10];
int *pa = &a[0];
*(pa + 3) = 6;
pa++; // pa now points to the next element of array, a[1]
There is no such element as "one past the last element", of course, but a pointer is
allowed to assume such a value. C "guarantees" that the result of addition is
defined even when pointing to one element past array. If
element,
page
72
,
, and
+
++
as advancing the pointer
has size of 10 bytes, then adding 5 to a pointer to
type
// array a containing 10 elements of int
// pa is pointer to int, pointing to a[0]
// pa+3 is a pointer pointing to a[3],
// so a[3] now equals 6
is legal, but
P+1
P+2
MikroElektronika: Development tools - Books - Compilers
to add an integral value to a pointer. The
+=
, adding an integral value to the pointer
type
by
(n*sizeof( type ))
P
type, size of the step is one byte.
void
is undefined.
mikroC
making it simple...
bytes, as long as the
advances
type
points to the last array
P

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?

This manual is also suitable for:

Pic microcontrollers pic16Pic microcontrollers pic18

Table of Contents