liveBook · Manning

Chapter 6: Derived data types

What you will learn in chapter 6 of Modern C, Third Edition

Introduces four ways C derives data types from basic types and distinguishes them from typedef, which gives an existing type a new name.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces four ways C derives data types from basic types and distinguishes them from typedef, which gives an existing type a new name.

Key terms: aggregate data types, arrays, structures, base type, pointers, unions, base types, typedef, new name, existing type

6.1 Arrays

Introduces arrays as objects that group elements of the same type and cautions that arrays are not pointers, despite their close relationship in C.

Key terms: arrays, pointers, objects, type

6.1.1 Array declaration

This section explains how array declarations describe elements and nested arrays, how subscripts reach their elements, and how designated initializers select positions.

Key terms: array, subobjects, base type, multidimensional array, array elements, subscript, C[0][0], designated initializers

6.1.2 Array operations

This section explains why arrays cannot be used as ordinary values in arithmetic, comparisons, or assignments, while noting that an array in a condition evaluates to true.

Key terms: array objects, array values, value operators, object operators, condition, array decay

6.1.3 Array length

This section distinguishes fixed- and variable-length arrays, explains their length rules and restrictions, and shows how to calculate an array’s length with sizeof.

Key terms: FLA, integer constant expression, ICE, initializer, VLA, default initializers, C99, C11, C23, automatic objects

6.1.4 Arrays as parameters

This section explains why array parameters lose dimension information and why a function can change the caller’s array.

Key terms: array parameter, innermost dimension, sizeof, passed by referenceC, swap_double(A)

6.1.5 Strings are special

This section explains what makes a char array a C string, how array and string library functions differ, and why missing termination can cause program failure.

Key terms: string, char, 0-terminated, string literal, basic character set, ASCII, <string.h>, memcpy, memcmp, memchr

6.2 Pointers as opaque types

This section introduces pointers as opaque references to data, explains their valid, null, and invalid states, and shows why they should always be initialized.

Key terms: pointer, opaque objects, initialization, assignment, evaluation, valid, null, invalid, nullptr, null pointer

6.3 Structures

This section introduces structures as a way to combine objects when array-style ordering is unsuitable or the objects have different types.

Key terms: arrays, base type, structures, struct

6.3.1 Simple structures to access fields by name

The section introduces named structure members through bird and calendar-time examples, then explains structure initialization, value passing, assignment, comparison limits, and the lasting importance of layout decisions.

Key terms: struct, members, fields, dot (.), struct birdStruct, struct initializer, struct tm, tm_wday, tm_yday, {}

6.3.2 Structures with fields of different types

This subsection shows that a struct can combine fields of different types, using nanosecond-resolution times as an example.

Key terms: struct, struct timespec, time_t, long, difftime, platform-specific properties

6.3.3 Nested structures

The section explains that structures can contain other structures and that declaring one structure inside another does not give it a separate scope.

Key terms: structure member, nested structures, VLA, scope of visibility, nested declaration, compound statement, layout

6.3.4 Coalescing structure fields

This section explains how structure padding and bit-fields affect storage, and how to choose bit-field types that represent values reliably.

Key terms: alignment, byte padding, structure member, bit padding, bit-field, coalescing, member designator, designated initializer, bare int, signed

6.4 New names for types: Type aliases

This section explains how typedef gives existing C types alternative names, shows an idiom for naming structures, and warns against defining names ending in _t.

Key terms: typedef, alias, type, struct, tag, forward declaration, _t, size_t, reserved

6.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 5: Basic values and data Chapter 7: Functions →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.