lecture 8-structure

lecture 8-structure - Structures and ADTs 1 Custom Data...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Structures and ADTs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 C gives you several ways to create a custom data type. The structure , which is a grouping of variables under one name and is called an aggregate data type. The typedef keyword, which defines a new name for an existing type. Custom Data Type
Background image of page 2
3 Structures A structure is a collection of variables referenced under one name , providing a convenient means of keeping related information together.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Structure Declaration A structure declaration forms a template that can be used to create structure objects (instances of a structure). The variables that make up the structure are called members . Usually, the members of a structure are logically related.
Background image of page 4
5 General Form struct tag { type member-name ; type member-name ; type member-name ; . . . } structure-variables ;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 struct addr { char name[30]; char street[40]; char city[20]; char state[3]; unsigned long int zip; }; Terminated by a semicolon keyword structure tag No variable has actually been created.
Background image of page 6
7 Structure Variable Declaration struct addr addr_info; declares a variable of type addr called addr_info . The compiler automatically allocates sufficient memory to accommodate all of its members.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Name 30 bytes Street 40 bytes City 20 bytes State 3 bytes Zip 4 bytes Assume 4-byte long integers Memory allocated for addr_info
Background image of page 8
9 struct addr { char name[30]; char street[40]; char city[20]; char state[3]; unsigned long int zip; } addr_info, binfo, cinfo; Declare one or more objects when declare a structure.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Initialization of Structures All External and Static Variables, including structure variables that are not explicitly initialized, - Are Automatically initialized to 0
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

lecture 8-structure - Structures and ADTs 1 Custom Data...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online