Real-Time Computing

1.10 C characters, pointers, strings, floats, and functions

Let us consider in greater detail a few C data types, their memory representations, and their type conversions.

1.10.1 Characters and casting

A char is a single-byte character. If one provides a character literal like 'A', the corresponding byte in memory holds a character code corresponding to A in the machine's character set—most commonly, ASCII (section 1.5.7). For instance, the seven-bit binary ASCII code for A is 1000001. It is preferable, of course, to use string literals like 'A' in C programming. However, we will occasionally need to manipulate character codes directly. Due to their integer nature, chars can be manipulated via integer arithmetic. For instance,

char x = 'A'; char y;  // ASCII character code 65