return  Character arrays

Chapter 1: Overview

Arrays

The format for an array declaration is:

data_type variable_name[size];

where

Table 1-14: Arrays

Array

Description

data_type

Datatype available in ODL.

variable_name

Name of the array.

size

Number of array elements.

You access an array element based on its index number. The index of the first element of an array is always 0 (zero) and each element is the next sequential number.

You may initialize the array elements at the time you declare the array, or later in your code. If you initialize the elements when you declare the array, then you may only initialize them to constants. ODL does not perform bounds checking on arrays. Therefore, it is possible to overrun the end of an array or access a nonexistent element. You may not assign one array to another.

Examples

This statement is invalid:

arr2 = arr1;

However, you can assign individual array elements; so, this statement is valid:

arr2[3] = arr2[5]

To declare an integer array named my_array with five elements, enter:

int my_array[5];

To declare and initialize the same array, enter:

int my_array[5] = {1, 3, 5, 7, 11};

To access the third element in the array, enter:

my_array[2];

To assign a value to the first element in the array, enter:

my_array[0] = 24;




Copyright © 2005. Sybase Inc. All rights reserved. Character arrays

View this book as PDF