**What is a structure?** A structure is *a collection of one or more variables grouped under a single name.* **Can variables inside of records be of different types?** *Yes*, variables inside of records can be of different types. **What do structures help with?** Structures help with *organizing complicated data.* > [!example] Example of where a structure would be useful > To store the payroll record for an employee. **Can structures contain variables which are other structures?** *Yes*, structures can contain variables which are other structures. **What change did the ANSI standard bring to structures in C?** The change the ANSI standard brought to structures in C was *defining structure assignment.* > **What are the four things you can do with assigning structures?** > The four things you can do with assigning structures are: > 1. Copying them. > 2. Assigning them to variables. > 3. Passing them to functions. > 4. Returning them. # 6.1 Basics of Structures > [!example] Example of creating a structure for a point in 2D space > ```c > struct point { > int x; > int y; > }; > ``` **What keyword is used to introduce a structure declaration?** The keyword used to introduce a structure declaration is *`struct`.* **What does the declaration of a struct comprise of?** The declaration of a struct is comprised of *a list of declarations enclosed in braces.* **What can be used with structs between the `struct` keyword and the opening brace?** Between the `struct` keyword and the opening brace, *a tag name* can be used. > **What is the purpose of a tag name for a struct?** > The purpose of a tag name for a struct is *to be a shorthand for the declaration between the braces.* **What are the variables inside of a structure called?** The variables inside of a structure are called *members.* **Can the names of normal variables and structure tag names or member names be the same?** *Yes*, the names of normal variables and structure tag names or member names can be the same. **What does the declaration of a structure define?** The declaration of a structure defines *a type.* **What can come after the closing brace of the declaration of a structure in C?** After the closing brace of the declaration of a structure, *a list of variables* can come after. **What does a structure declaration do if it isn't followed by a list of variables?** If a structure declaration isn't followed by a list of variables, *it just defines a template.* > [!example] Example of creating a variable called `pt` which uses a struct with the tag name `point` > ```c > struct point pt; > ``` **How do you initialize the members of a struct?** You initialize the members of a struct *by following its definition with a list of initializers between braces.* > **What do the initializers for the members of a struct have to be?** > The initializers for the members of a struct have to be *constant expressions.* > [!example] Example of creating a variable called `pt` which uses a struct with the tag name `point` and assigns `320` and `200` to the `x` and `y` struct members respectively > ```c > struct point pt = { 320, 200 }; > ``` **Which operator is used to access the members of a structure?** To operator used to access the members of a structure is *the dot operator (`.`).* > [!example] Example of accessing the `x` member of `pt` if `pt` is a `point` struct > ```c > pt.x; > ``` ... # 6.2 Structures and Functions ...