liveBook · Manning

Size_t

As explained in Modern C

size_t is an unsigned integer type provided by the C standard library for representing object sizes and related counts.

   size_t a = 45;
   size_t b = 7;
   size_t c = (a - b)*2;
   size_t d = a - b*2;


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}],[{\"line\":0,\"ch\":3},{\"line\":0,\"ch\":9}],[{\"line\":1,\"ch\":3},{\"line\":1,\"ch\":9}],[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":9}],[{\"line\":3,\"ch\":3},{\"line\":3,\"ch\":9}]]"}
!@%STYLE%@!

Start with four size_t values and two parenthesized expressions. With a = 45 and b = 7, c becomes 76 while d becomes 31, showing how grouping changes the computation. section 4.1.1

size_t is an unsigned semantic type for sizes and cardinalities. Unlike types specified directly with keywords such as unsigned or int, it is specified through a header file and communicates the intended meaning of a value. The type is defined in stddef.h. section 5.2

The arithmetic rules are precise:

  • The operators +, -, and * on size_t produce the mathematically correct result whenever that result is representable in size_t. section 4.1.1
  • Unsigned arithmetic is well defined, including negation and subtraction; results outside the range [0, SIZE_MAX] are arithmetic overflow. section 4.1.1
  • size_t belongs to the unsigned-integer family, while its semantic naming emphasizes sizes rather than merely the machine representation. section 5.2

Unary operators

The expression (+a + -b) * 2 uses unary + to provide a value and unary - to produce its negative before multiplication. For unsigned size_t values, this negation and subtraction remain well defined. section 4.1.1

How Modern C covers it

How deep it goes
Explains size_t’s semantic classification and +, -, and * rules, but defers detailed overflow handling.
Examples
Demonstrates grouped expressions, unary operators, and values 45 and 7 producing 76 and 31.
What it assumes
Assumes basic familiarity with C expressions and introduces semantic type specifications alongside unsigned-integer categories.
What you can do after
Evaluate/understand size_t expressions and recognize when unsigned results are representable or overflow.
How it connects
Connects size_t with unsigned integers, arithmetic overflow, basic types, and header-defined semantic types.

Also explained in

Compare how 2 books explain size_t →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.