Key Features of Arrays:
- Definition: Arrays are data structures that store a group of elements of the same data type.
- Naming: All elements share the same name, differentiated by an index.
- Access: Elements can be accessed randomly using a numeric index.
- Simplicity: Arrays are simple and have been used for decades, offering great utility.
- ADT List: Frequently associated with the Abstract Data Type (ADT) list.
Array Declaration
Syntax: data-type array_name [constant-size]; where, Data-type: The type of elements stored and Constant-size: The number of elements.
Examples:
- int num[80];
- float farr[500];
- static int iarr[80];
Restrictions:
- Fixed Size: The storage amount must be specified at compile time
- Homogeneity: All elements in an array must be of the same data type.
Size Specification
Use symbolic constants for array sizes for easier modifications. Example:
#define SIZE 50
int arr[SIZE];