1 / 6

Arrays - PowerPoint PPT Presentation

Arrays. Robert Reaves. 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:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about ' Arrays' - kennan

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Arrays

Robert Reaves

• 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 ];

• Array Component Access:

• ArrayName [ IndexExpresson ]

• 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.

• 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};

• I/O -> No

• Assignment -> No

• Comparison -> No

• Argument Passage -> By reference

• Return as a function’s return value -> No