Typedef uses
- It is a simple substitution of an existing data type for a new one
- Effectively it is a new name for the same data
- One common use is creating data types that are more descriptive:
- typedef unsigned char uint8;
- typedef unsigned int uint32;
- Now variable bit sizes are easily seen
- Also has uses when writing code that may run on different processors and platforms.
- What if we wanted to create a more advanced data type?
- Something that could organize several bytes into something new.
- Something more than a simple substitution….
Structs
- Structs are used primarily for organization of data types.
- Say we are tracking someone’s birthday.
- int year, month, day;
- However those three variables can be considered as one, a date.
- We can create a new data type to hold all of this data and keep it organized.
- Should be created in a logical manner, the variables within the new data type are a piece of it.
- What may be the components to a data type BankCustomer?
- Name
- Account Number
- Balance
Creating Structs Part 1
First method:


