100 likes | 276 Views
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.
E N D
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
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
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.
The Code }
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.
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. }
Alternative Example • U.S. Social Security Information http://a323.yahoofs.com/ymg/null__15/null-60857159-1246979568.jpg?ymwnPiBDXIS2ujp4
Any Questions? http://i.ehow.com/images/a04/eu/2b/teach-child-answer-questions-800X800.jpg