

Structures in C
Presentation
•
Computers
•
12th Grade
•
Easy
Used 14+ times
FREE Resource
13 Slides • 9 Questions
1
Structures in C

2
Lesson Objectives:
Define the term 'structure' as it relates to programming.
Differentiate between a structure and an array.
Implement structures in C programming.
3
What is a structure?
A structure is a user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type.
4
How does a structure differ from an array?
Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.
5
Multiple Choice
A structures are similar to array in that they can store multiple data items.
True
False
6
Multiple Choice
A structures are similar to array in that they can store multiple data items.
True
False
7
Understanding structures
Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book −
* Title
* Author
* Subject
* Book ID
8
Defining a structure
To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member. The format of the struct statement is as follows −
struct [structure tag] {
------member definition;
------ member definition;
------ ...
------member definition;
} [one or more structure variables];
9
Example of Structure Definition
The structure tag is optional and each member definition is a normal variable definition, such as int i; or float f; or any other valid variable definition. At the end of the structure's definition, before the final semicolon, you can specify one or more structure variables but it is optional. Here is the way you would declare the Book structure −
10
Multiple Choice
How many members does struct Books contain?
1
0
3
4
11
Multiple Choice
How many data types are in struct Books?
1
2
3
4
12
Accessing Structure Members
To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use the keyword struct to define variables of structure type. The following example shows how to use a structure in a program −
13
14
Using typedef with struct
typedef is a keyword used in C language to assign alternative names to existing datatypes. Its mostly used with user defined datatypes, when names of the datatypes become slightly complicated to use in programs.
15
Using typedef with struct
typedef is a keyword used in C language to assign alternative names to existing datatypes. Its mostly used with user defined datatypes, when names of the datatypes become slightly complicated to use in programs.
16
17
Open Ended
Which structure variable name are the members of struct Books being accessed using?
18
Open Ended
Respond to the following:
A car dealership desires to store the following information on vehicles:
*year
*brand
*model
*price
Define a struct 'Cars' to store the data.
19
Open Ended
Write a line of code giving struct Cars an alternate name.
20
Open Ended
Write a line of code to store the value 2020 in the year variable using the alternative struct name you declared.
21
Time to Code!!!
Open your C compiler and let's have some FUN :)
22
Open Ended
Your response here
Structures in C

Show answer
Auto Play
Slide 1 / 22
SLIDE
Similar Resources on Wayground
21 questions
Chromebook Tips Lesson
Presentation
•
12th Grade
16 questions
The Theory of Evolution
Presentation
•
8th Grade
18 questions
In-Text Citation (Direct Quote, Paraphrasing, Summarizing)
Presentation
•
12th Grade
18 questions
El amor 1. Thich y Eterno resplandor
Presentation
•
KG
16 questions
Pseudocode
Presentation
•
12th Grade
15 questions
APPLICATION LETTER
Presentation
•
12th Grade
15 questions
digestive system
Presentation
•
12th Grade
19 questions
Causes and effects of the Great Depression
Presentation
•
12th Grade
Popular Resources on Wayground
5 questions
A Home on the Shore
Quiz
•
3rd Grade
28 questions
US History Regents Review
Quiz
•
11th Grade
6 questions
A Horse Tale
Quiz
•
3rd Grade
20 questions
Math Review
Quiz
•
3rd Grade
10 questions
Juneteenth History and Significance
Interactive video
•
5th - 8th Grade
20 questions
Dividing Fractions
Quiz
•
5th Grade
55 questions
A Long Walk to Water Final Review
Quiz
•
6th - 8th Grade
10 questions
Equation Word Problems
Quiz
•
7th Grade
Discover more resources for Computers
20 questions
Insurance
Quiz
•
9th - 12th Grade
10 questions
Juneteenth: History and Significance
Interactive video
•
7th - 12th Grade
6 questions
Mayan Mathematics part 1
Presentation
•
9th - 12th Grade
40 questions
Flags of the World
Quiz
•
KG - Professional Dev...
10 questions
Unit 9 Quiz
Quiz
•
9th - 12th Grade