liveBook · Manning

Char(n)

As explained in Modern C

char is the C integer type used to represent characters and small integer values.

char is a narrow integer type used to encode characters from C’s basic character set and to represent small integer values. That set includes Latin letters, digits, and coding punctuation; special and non-Latin characters usually lie outside it. Most platforms use ASCII transparently. section 6.1.5

Character arrays and strings

char jay0[] = "jay"; creates a string with four elements: 'j', 'a', 'y', and a terminating 0. Equivalent initializations can write the characters explicitly. By contrast, char jay4[3] = { 'j', 'a', 'y' }; has no room for the terminator and is not a string. TAKEAWAY: a string is a 0-terminated array of char. section 6.1.5

Use the standard library according to whether an object is merely a char array or a 0-terminated string:

  • Use memcpy, memcmp, and memchr with char arrays when an explicit length is available. section 6.1.5
  • Use strlen, strcpy, strcmp, and related str functions only with strings. section 6.1.5

How Modern C covers it

How deep it goes
Explains representation, termination, initialization, encoding assumptions, and library interfaces, but defers broader integer details.
Examples
Uses jay initializers and a complete program copying argv[0] into a variable-length char array.
What it assumes
Assumes basic C declarations and arrays while defining strings, termination, and character encoding in context.
What you can do after
Apply it via string.h by distinguishing terminated strings from length-bounded char arrays.
How it connects
Connects char with strings, arrays, integer types, ASCII, and the standard library.

Also explained in

Compare how 5 books explain char(n) →

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.