kennan
Uploaded by
6 SLIDES
207 VUES
60LIKES

Understanding One-Dimensional Arrays: Structure, Access, and Initialization

DESCRIPTION

One-dimensional arrays are structured collections of components accessed individually by a single index. Also known as arrays of elements, they are defined in C++ with syntax such as DataType ArrayName[ConstIntExpression]. Accessing individual components is done via ArrayName[IndexExpression]. Caution is required with out-of-bounds indexes, as accessing memory beyond allocated limits may result in segmentation faults. Arrays can be initialized at declaration (e.g., int a[5] = {23, 10, 16, 37, 12};) and the size can be omitted if initialized simultaneously. However, they lack support for aggregated operations.

1 / 6

Download Presentation
Télécharger la présentation

Understanding One-Dimensional Arrays: Structure, Access, and Initialization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arrays Robert Reaves

  2. One-Dimensional Array • One-Dimensional Array is a structured collection of components that can be accessed individually by specifying the position of a component with a single index value. • Also called an array of elements. • Declaration: • DataTypeArrayName [ ConstIntExpression ];

  3. Accessing Individual Components of an Array • Array Component Access: • ArrayName [ IndexExpresson ]

  4. Out-of-Bounds Array Indexes • Given: • float alpha[100]; • What happens if we execute this statement when i = 0 or i > 99? • alpha[i] = 62.4; • We get a Segmentation Fault. • Meaning you are accessing memory that is allocated.

  5. Initializing Arrays in Declarations • int a[5] = {23, 10, 16, 37, 12}; • Where: • a[0] will = 23 • a[1] will = 10 • a[2] will = 16 • a[3] will = 37 • a[4] will = 12 • Can also omit the size of the array if you use this type of declaration and initialization. (With C++) • int a[] = {23, 10, 16, 37, 12};

  6. (Lack of) Aggregated Operations • I/O -> No • Assignment -> No • Comparison -> No • Argument Passage -> By reference • Return as a function’s return value -> No

More Related
SlideServe
Audio
Live Player
Audio Wave
Play slide audio to activate visualizer