

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Memory
incomplete
2: What Is an Address?
incomplete
3: Virtual Memory
incomplete
4: Pointers
incomplete
5: Why Pointers?
incomplete
6: Pointer Basics
incomplete
7: Pointers to Structs
incomplete
8: C Arrays
incomplete
9: Arrays As Pointers in C
incomplete
10: Multibyte Arrays
incomplete
11: Array Casting
incomplete
12: Pointer Size
incomplete
13: Arrays Decay to Pointers
incomplete
14: C Strings
incomplete
15: C String Library
incomplete
16: Forward Declaration
incomplete
17: Mutual Structs
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Forward declarations can also be used when two structs reference each other (a circular reference). For example, a Person has a Computer and a Computer has a Person:
typedef struct Computer computer_t;
typedef struct Person person_t;
struct Person {
char *name;
computer_t *computer;
};
struct Computer {
char *brand;
person_t *owner;
};
Notice that the struct definitions end with just }; rather than } person_t;. Since we already created the typedef aliases in the forward declarations, we don't need to repeat them, though both styles are valid in C.
Note that when you use forward declarations, you must use pointers to incomplete types (Computer *computer;), not full values (Computer computer;). This is because the size of the struct is unknown.
Complete the definitions of the Employee and Department structs. Take a look at the implementations in the .c file to understand how they should be defined.
A manager is just another employee_t.