Presentation is loading. Please wait.

Presentation is loading. Please wait.

C Structures, Unions, Bit Manipulations and Enumerations

Similar presentations


Presentation on theme: "C Structures, Unions, Bit Manipulations and Enumerations"— Presentation transcript:

1 C Structures, Unions, Bit Manipulations and Enumerations
Lab guide #9 C Structures, Unions, Bit Manipulations and Enumerations Review & Lab Assignments

2 Key points Understanding & using Bitwise operators. Structures Unions
Enumerations. Bitwise operators.

3 Structure Structure: Definition: 2 ways Accessing structure members
collection of related variables struct card { char *face; char *suit; }; Definition: 2 ways card oneCard, deck[ 52 ], *cPtr; Or: char *suit; } oneCard, deck[ 52 ], *cPtr; Accessing structure members (.) used with structure variables (->) used with pointers to structure variables typedef: create shorter type names typedef struct Card *CardPtr;

4 Unions Union: like structure but union definitions
Only contains one data member at a time Members of a union share space Only the last data member defined can be accessed union definitions Same as struct union Number { int x; float y; }; union Number value;

5 Enumeration Enumeration
Set of integer constants represented by identifiers Values are automatically set Example: enum Months { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}; Creates a new type enum Months in which the identifiers are set to the integers 1 to 12 Enumeration variables can only assume their enumeration constant values (not the integer representations)

6 10.9 Bitwise Operators

7 Bit Fields Bit field : Enable better memory utilization
struct BitCard { unsigned face : 4; unsigned suit : 2; unsigned color : 1; }; Must be defined as int or unsigned Cannot access individual bits Member of a structure whose size (in bits) has been specified

8 Lab assignments fig10_02.c (lecture note)
fig10_09.c (lecture note) ( Checking if we have time) Problem 10.9 (C How to program – Fifth Edition – the question is below)


Download ppt "C Structures, Unions, Bit Manipulations and Enumerations"

Similar presentations


Ads by Google