mikroElektronika PIC Microcontrollers PIC12 User Manual page 81

Mikroc user's manual
Table of Contents

Advertisement

mikroC
making it simple...
This allows you to write loops which access the array elements in a sequence by
means of incrementing pointer — in the last iteration you will have a pointer
pointing to one element past an array, which is legal. However, applying the indi-
rection operator (
behavior.
For example:
void f (some_type a[], int n) {
int i;
some_type *p = &a[0];
for (i = 0; i < n; i++) {
}
/* at this point, *p is undefined! */
}
Pointer Subtraction
Similar to addition, you can use operators
value from a pointer.
Also, you may subtract two pointers. Difference will equal the distance between
the two pointed addresses, in bytes.
For example:
int a[10];
int *pi1 = &a[0], *pi2 = &[4];
i = pi2 - pi1;
pi2 -= (i >> 1);
MikroElektronika: Development tools - Books - Compilers
) to a "pointer to one past the last element" leads to undefined
*
/* function f handles elements of array a; */
/* array a has n elements of some_type */
/* .. here we do something with *p .. */
/* .. and with the last iteration p exceeds
p++;
the last element of array a */
// i equals 8
// pi2 = pi2 - 4: pi2 now points to a[0]
mikroC - C Compiler for Microchip PIC microcontrollers
,
, and
-
--
-=
to subtract an integral
73
page

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