Null termination
Null termination is the convention of marking the end of a character sequence with a zero-valued character or byte.
Refactoring to Rust
A C string is a contiguous character sequence terminated by a null character.
- How it is used
- Bridges null-terminated C input into borrowed Rust string slices during C FFI.
- How deep it goes
- Explains layout, borrowing, allocation avoidance, and UTF-8 validation, but does not develop string parsing beyond conversion.
- Examples
- Uses a C calculator line buffer, CStr::from_ptr, to_str, and matching pointer addresses to demonstrate shared memory.
- What you can do after
- Apply it via CStr and to_str to read C-owned input without duplicating its allocation.
Systems Programming with Zig
A NUL terminator is a zero byte placed after text data to mark the end of a byte string.
- How it is used
- Bridges Zig string literals to C functions and represents C strings without carrying slice lengths.
- How deep it goes
- Explains the zero-byte boundary and Zig sentinel-pointer types, while deferring other uses of sentinel values.
- Examples
- Shows a string literal typed as `*const [21:0]u8` and explains direct C-function passing.
- What you can do after
- Apply Zig sentinel-pointer types to pass string literals to C functions without copying.
Read how Systems Programming with Zig explains null termination →
Also covered in
- Embedded Software with RustIn early access (MEAP)
- Modern C, Third Edition
What to know first
- sliceA slice is a non-owning view of a portion of a contiguous sequence of elements, typically represented by a pointer and a length.
Related concepts
- string literalused by · A string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
- null characteruses · A null character is the zero-valued character U+0000, commonly represented by a zero byte and used to terminate C-style strings.
Questions about null termination
What is null termination?
Null termination is the convention of marking the end of a character sequence with a zero-valued character or byte.
Which Manning books explain null termination?
Refactoring to Rust and Systems Programming with Zig.
What should I know before learning null termination?
Manning books that teach null termination usually introduce slice first.
What is null termination part of?
Null termination is part of C string. A C string is a sequence of character bytes terminated by a zero-valued byte, with its length determined by the terminator rather than stored separately.
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.

