Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 74

Advertising
background image

Array Initialization

Array can be initialized in declaration by assigning it a comma-delimited sequence
of values within braces. When initializing an array in declaration, you can omit the
number of elements – it will be automatically determined acording to the number
of elements assigned. For example:

/* An array which holds number of days in each month: */

int

days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

/* This declaration is identical to the previous one */

int

days[] = {31,28,31,30,31,30,31,31,30,31,30,31};

If you specify both the length and starting values, the number of starting values
must not exceed the specified length. Vice versa is possible, when the trailing
“excess” elements will be assigned some encountered runtime values from memo-
ry.

In case of array of

char

, you can use a shorter string literal notation. For example:

/* The two declarations are identical: */

const char

msg1[] = {'T', 'e', 's', 't', '\0'};

const char

msg2[] = "Test";

For more information on string literals, refer to String Constants.

Arrays in Expressions

When name of the array comes up in expression evaluation (except with operators

&

and

sizeof

), it is implicitly converted to the pointer pointing to array’s first

element. See Arrays and Pointers for more information.

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

66

MikroElektronika: Development tools - Books - Compilers

page

Advertising
This manual is related to the following products: