Key Concepts

Review core concepts you need to learn to master this subject

Defining Structures With struct

// `struct` keyword and structure name struct Person{ // uninitialized member variables char* name; int age; };

Structures are defined with the struct keyword followed by the structure name. Inside the braces, member variables are declared but not initialized. The given code block defines a structure named Person with declared member variables name and age.

Structures: Lesson
Lesson 1 of 1
  1. 1
    Throughout this course, we have defined many different variable types like, int and char. These are known as the basic types and are built-in to C. We’ve also defined data types like arrays and p…
  2. 2
    To help us understand how to include structures (also called structs) in our code, let’s look at how to define them: ![Structure components, the keyword struct, the name Bottle and member variable…
  3. 3
    Now that we know how to define structures, let’s take a look at how we can use them in our code. struct Bottle { char* name; int maxCapacity; int currentCapacity; }; struct Bottle bottle1 = …
  4. 4
    Let’s now take a step back and discuss why we would want to use structures. Look at an example of a program that uses bottle data without structures. char bottleName1[] = “Medium Bottle”; int …
  5. 5
    Now that we’ve leveraged that power of structures to package variables together we can discuss how we can access each member variable individually using dot notation. Dot notation is a C operato…
  6. 6
    Similar to other derived types, like arrays and strings, structures can use a lot of memory. Imagine a structure with multiple strings each able to hold hundreds of characters. One way to manage …
  7. 7
    Let’s wrap up by using structures with functions. We can specify structures and pointers to structures as parameters to functions: void myFunction(struct Bottle b, struct Bottle* bPointer) When p…
  8. 8
    Great job learning about structures! We’ve covered many important topics: - Structures allow you to create user-defined data types - Structures can package together other data types into one type -…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo