Professional Documents
Culture Documents
Object Oriented Programming
Object Oriented Programming
Object Oriented Programming
Structures
Union
Bit-field
Enumeration
typedef
Structures
If you need only one variable you can skip the stuct tag.
Stuctures (How to use)
To access a specific structure, index the array name. For example, to print
the ZIP code of structure 3, write
Passing structures to functions
C allows pointers to structures just like pointer to any other type of object.
Structure pointers are declared by placing * in front of a structure
variable's name
For example,
To place the address of person
into pointer p
Structure pointer
The –>, usually called the arrow operator, consists of the minus sign
followed by a greater than sign.
The arrow is used in place of the dot operator when you are accessing a
structure member through a pointer to the structure.
Unions
C has a built-in feature, called a bit-field, that allows you to access a single
bit
Why to use?
If storage is limited, you can store several Boolean (true/false) variables in one
byte
Certain devices transmit status information encoded into one or more bits within
a byte
Certain encryption routines need to access the bits within a byte
Bit-Fields
Enumeration
You can also change the values, here penny=0, nickel=1, dime =2, quarter
= 100, half_dollar = 101, dollar = 102
Typedef
You can define new data type names by using the keyword typedef
The following will set a new name for balance which is another name for float
Thank you!