1️⃣

4.1 What are Structures?

 

What are Structures?

Recall that arrays in C can store multiple of the same data type. (Look back at Chapter 7 if you need to know about arrays).
 
#include <stdio.h> int main(void) { int DigitsofPi[10] = {3, 1, 4, 1, 5, 9, 2, 6, 9, 3} }
 
The array solely contains integers. But what if we wanted to alternate between numbers and their spellings?
 
#include <stdio.h> int main(void) { int DigitsofPi[10] = {3, "one", 4, "one", 5, "nine", 2, "six", 9, "three"} } >> ERROR
 
The array would produce an error since it cannot hold 2 different data types. However, a structure on the other hand is able to hold multiple variable types at once.

Next Section

2️⃣
4.2 Structure Syntax
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.