1 / 9

Pointer Array of Structures

Pointer Array of Structures. Tiffany P. Hall Miguel Valdes. Outline. Elements Required Block diagram of how elements go together Main code function to implement objectives Code function for elements How program operates Alternative Example. http://www.marcomm.ca/images/CorpOverview.JPG.

cybil
Download Presentation

Pointer Array of Structures

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. Pointer Array of Structures Tiffany P. Hall Miguel Valdes

  2. Outline • Elements Required • Block diagram of how elements go together • Main code function to implement objectives • Code function for elements • How program operates • Alternative Example http://www.marcomm.ca/images/CorpOverview.JPG

  3. Elements Required • Struct: introducer of structure definition • Tag: follows struct; used to name definition • Together, Struct and Tag declare variables of structure type • Variables: structures’ members • Self-referential structure: contains a pointer that directs to the same structure type. Build linked data structures • Pointer: variables whose values are memory addresses • For example • With the definitions int y = 5; int *yPtr; the statement yPtr = &y assigns address of variable y to pointer variable

  4. Block Diagram of Elements • Define a structure, then declare and initialize */ /* an array of 4 structures. • After char name, declare a pointer to type part, and a counter variable. • After data, declare a pointer to type part, and a counter variable. • After main void, initialize the pointer to the first array element. • After p_part = data, loop through the array, incrementing the pointer with each iteration.

  5. The Code }

  6. How Program Operates • Overall • A pointer is a memory address.  • A structure is used to declare  new data types  • In this example a pointer is used to step through the array of structures which consists of a number and a Last name, grouped together by the structure.

  7. How the Program Operates (Cont’d) • Step by Step:  • Step 1 - the standard input/output header is included and the function MAX 4 is declared. • Step 2 - Struct is used to group variables together, for example, 1-Smith, 2-Jones and so on.  • Step 3 - count is declared and initialized • Step 4 - Inside the main function, a pointer to the first element of the array is initialized.  • Step 5 - A for loop is used to loop through the array four times. Each time the program will print the address of each element and then the pointer will be incremented.  }

  8. Alternative Example • U.S. Social Security Information http://a323.yahoofs.com/ymg/null__15/null-60857159-1246979568.jpg?ymwnPiBDXIS2ujp4

  9. Any Questions? http://i.ehow.com/images/a04/eu/2b/teach-child-answer-questions-800X800.jpg

More Related