CSE1320Ch7Notes - CH 7 C Structures Unions Bit...

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

View Full Document Right Arrow Icon
CH. 7 -- C Structures, Unions, Bit Manipulations and Enumerations I. Introduction A. Scalar -- one of something (an integer, a double, etc.) B. Aggregate -- a collection of variables 1. A collection of variables of the same data type a. an array b. an enumeration 2. A collection of variables of possibly different types a. a structure b. a union II. Structure Definitions A. 'struct' keyword B. Required tokens C. Structure tag (optional) D. Structure members 1. If several members have the same type, the member names must be different 2. Two different structure definitions can contain members with the same name 3. A structure cannot contain an instance of itself E. Does not reserve any memory--memory is reserved only when an object of that structure is instantiated F. Instantiating objects of a structure 1. struct { ... } X, *Xptr, Y[2], *Z[3]; // can only declare here if no tag 2. struct A { ... } X, *Yptr;
Background image of page 1

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

View Full DocumentRight Arrow Icon
struct A AObject, *Aptr, *C[3], D[2]; 4. When an structure object is created, all members of the object will exist at the same time, each in its own memory space. 5. The size of a structure object is the sum of the sizes of its members. G. The only valid operations that may be performed on structures are 1. assignment, using two structure variables of the same type 2. address 3. dereferencing a. '.' operator if using an object of a structure b. '->' operator if using a pointer to a structure H. DO NOT compare structures with '==' or '!=' III. Initializing an object of a structure A. struct card { char *face; char *suit; }; B. struct card aCard = {"Three", "Hearts"); C. struct card aCard; strcpy(aCard.face, "Three"); // segmentation fault strcpy(aCard.suit, "Hearts"); // segmentatation fault D. struct card aCard; aCard.face = (char *) malloc(20 * sizeof(char)); strcpy(aCard.face, "Three"); E. Structure variables defined outside of a function definition (i.e., "externally") are initialized to 0 or NULL if they are not explicitly initialized in the external defiinition. IV.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/14/2008 for the course CSE 1320 taught by Professor Sprintston during the Spring '08 term at UT Arlington.

Page1 / 9

CSE1320Ch7Notes - CH 7 C Structures Unions Bit...

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

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