

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
17 questions
Food Chain/Food Web Recap
Presentation
•
12th Grade
18 questions
JANJANG
Presentation
•
12th Grade
19 questions
ECONOMICS TOPIC 1 LESSON 2
Presentation
•
12th Grade
16 questions
Review Text Bahasa Inggris Peminatan
Presentation
•
12th Grade
16 questions
Widget
Presentation
•
12th Grade
18 questions
Empowerment Technologies Subject Orientation
Presentation
•
12th Grade
17 questions
G12Q2W1L1- Digital Rights and Responsibilities
Presentation
•
12th Grade
20 questions
Get Smart Plus 3 Topic 8 was/were
Presentation
•
1st - 4th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
MyPath Diagnostic Overview
Presentation
•
6th - 8th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Adding and Subtracting Decimals
Quiz
•
5th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
21 questions
Lab Safety
Quiz
•
10th Grade