1 / 6

Introduction To Arrays

Introduction To Arrays. Arrays are designed to handle large amounts of data of the same type in an organized manner. Using arrays permits us to set aside a group of memory locations that we can then manipulate as a single entity or have direct access to any component.

marli
Download Presentation

Introduction To 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. Introduction To Arrays Arrays are designed to handle large amounts of data of the same type in an organized manner. Using arrays permits us to set aside a group of memory locations that we can then manipulate as a single entity or have direct access to any component. Arrays may be used for alphabetizing a list of names, analyzing a list of test scores, manipulating character data, and keeping an inventory. Let us at this point work with a list of five integers: 18, 17, 21, 18, and 19. Prior to this chapter, we would have declared five variables--A, B, C, D, and E--and assigned them appropriate values. This would have produced five values in memory each accessed by a separate identifier. int Data [5];

  2. Array Cells printf ("EvenNos = &%x\n", EvenNos); printf ("EvenNos = &%x\n", &EvenNos); ? ? int Data [5]; The five individual portions of the array are referred to as cells or components or elements of the array. ? ? EvenNos = &2753454 EvenNos = &2753454 ? &2753454 Data

  3. 8 EvenNos[0] = 0; EvenNos [1] = 2; EvenNos [2] = 4; EvenNos [3] = 6; EvenNos [4] = 8; Filling The Array 6 4 2 0 int EvenNos[5]; &2753454 EvenNos for (Index = 0; Index < 10; Index ++) EvenNos [Index] = Index * 2;

  4. for (Index = 4; Index >= 0; Index --) { printf (" |--------|\n"); printf ("%d : EvenNos [%d] => %x | %3d |\n", Index, Index, &EvenNos[Index], EvenNos[Index]); } printf (" |--------|\n"); 8 Displaying The Array 6 4 2 0 short int EvenNos[5]; &2753454 EvenNos

  5. Use the define statement for the MAX_NOS so that it is easier to change the size of your arrays as programs grow. # define MAX_NOS 100 int EvenNos [MAX_NOS]; for (Index = MAX_NOS - 1; Index >= 0; Index --) EvenNos [Index] = 2 * Index; for (Index = MAX_NOS - 1; Index >= 0; Index --) { printf(" |--------|\n"); printf ("%3d : EvenNos [ %2d ] => %x | %3d |\n", Index,Index, &EvenNos [Index], EvenNos [Index]); } printf (" |--------|\n"); 8 Defining Constants Add Flexability 6 4 2 EvenNos 0

  6. Use the define statement for the MAX_NOS so that it is easier to change the size of your arrays as programs grow. # define MAX_NOS 100 int EvenNos [MAX_NOS]; for (Index = MAX_NOS - 1; Index >= 0; Index --) EvenNos [Index] = 2 * Index; for (Index = MAX_NOS - 1; Index >= 0; Index --) { printf(" |--------|\n"); printf ("%3d : EvenNos [ %2d ] => %x | %3d |\n", Index,Index, &EvenNos [Index], EvenNos [Index]); } printf (" |--------|\n"); 8 cc 6 4 2 EvenNos 0

More Related