W5 - STRUCTURES Flashcards
W5-1: What is STRUCTURE?
_ The most commonly used data structure in (C) programs aside from the array is the STRUCT or STRUCTURE
_ A STRUCTURE type is a collection of NOT necessarily IDENTICAL types
_ use the STRUCTURE type to define a GROUP of variables as a SINGLE object
W5-2: What is a TYPE?
_ A TYPE describes how to interpret the INFO stored in a region of MEMORY
_ In (C), a type may be a PRIMITIVE type or a DERIVED type
_ A DERIVED type is a collection of other types
W5-3: PRIMITIVE TYPES include:
1/ char 2/ int
3/ float 4/double
Each type defines how a VALUE of that type is stored in a region of MEMORY.
Consider the int type. A value of int type is stored in equivalent BINARY representation in 4 bytes on a 32-bit platform
W5-4: DERIVED TYPES
The declaration of a derived type in (C) takes the form: struct Tag { //... declarations here };
struct identifies a derived type or structure
Tag is the name by which we call the structure
The declaration concludes with a semi-colon.
W5-5: INITIALIZATION
_ To initialize an object of a structure, add a braces-enclosed, comma-separated list of values.
_ organize the INITIAL values in the SAME ORDER as the member listing in the declaration of the structure.
_ The initialization takes the form
struct Tag identifier = { value, … , value };