1 / 4

ARRAYS

ARRAYS. Arrays are data structures consisting of related data items of the same type. An array is a group of memory locations – where the elements of the array have the same name and same datatype.

elewa
Download Presentation

ARRAYS

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 • Arrays are data structures consisting of related data items of the same type. • An array is a group of memory locations – where the elements of the array have the same name and same datatype. • To refer to a particular element in the array, we specify the name of the array and the position number of the particular element. • The first element in every array is the zeroth element. • The position number contained within square brackets is called a subscript.

  2. Name of the array a[0] a[1] a[2] a[3] a[4] a[5] a[6] Position number/Subscript

  3. Declaring And Initializing Arrays • float a[20]; a is a float array consisting of 20 elements. • int a[8] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 }; The elements of array a are initialized to the values in braces.

  4. /* Program to calculate the sum of the elements in the array */ #include <stdio.h> #define SIZE 8 int main() { int a[ SIZE ] = {1, 2, 3, 4, 5, 6, 7, 8}; int j , sum = 0; for ( j = 0; j <= SIZE –1 ; j++) sum += a[ j ]; printf(“Sum of the elements is %d “,sum); }

More Related